Yii Framework Forum: Returning A Sorted Table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Returning A Sorted Table Rate Topic: -----

#1 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

Posted 13 October 2012 - 05:29 AM

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
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 677
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 13 October 2012 - 07:12 AM

you can set the entry_id order to DESC
0

#3 User is offline   Sler 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 17-July 12

Posted 13 October 2012 - 08:52 AM

View Postalirz23, on 13 October 2012 - 07:12 AM, said:

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?
0

#4 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 677
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 14 October 2012 - 01:48 AM

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

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users