Returning A Sorted Table

Hello, I have a price table which has : entry_id, crop_id, price, user, date_eff attributes

For example my $cropId = 5


$price=Price::model()->find('crop_id = :cropId', array(

				':cropId' => $cropId));

This code will search a crop id in the model Price and returns the price in return.

But what if I have this table.

entry_id | crop id | price | date_eff |


1 | 5 | 34 | today |

2 | 3 | 32 | now |

3 | 5 | 324 | yesterday |

When I execute the code above, it will return the price of the first it sees. In this case, entry_id = 1, I would like for the latest entry to show. I would like entry_id = 3 or the price 324. not the first entry

you can set the entry_id order to DESC

I’ve tried that but it didn’t work it. Can you please expand where to put the code and what file?


YourModelName::model()->find(array("condition"="cropId=:cropId", "params"=>array(":cropId"=> youridvariable), "order" => "entry_id DESC")