If this mysql statement is
$price = mysql_query("SELECT price FROM price where crop_Id = $cropId");
In Yii
$price=Price::model()->find(‘crop_id = :cropId’, array(
':cropId' => $cropId
) );
What about
$price = mysql_query("SELECT price FROM price where crop_Id = $cropId ORDER BY entry_id DESC");? how to write it in yii?
You can pass CDbCriteria to find() or use associative array, like this
Price::model()->find(array('condition' => '...', 'order'=>'entryId DESC'), ...)
I have this current code now
$price=Price::model()->find(array(‘condition’ => ‘crop_id = :cropId’, array(
':cropId' => $cropId), 'order'=>'entry_id DESC'));
Property "CDbCriteria.0" is not defined.
Got the problem: used this insteaad
$price=Price::model()->findAll('crop_id = :cropId', array(
':cropId' => $cropId
));
$view_price = array();
$y=0;
foreach($price as $c)
{
$view_price[$y] = strtolower($c->entry_id);
$y++;
}
$view_max = count($view_price) - 1;
$latest = $view_price[$view_max];
$price=Price::model()->find('entry_id = :latest', array(':latest' => $latest));