开发者

list the Data in sequential order according to the Date

I am learning cakePHP 1.26.

I got some sample data in a Table Testin开发者_JS百科g which consists of two fields:

(there is not primary key in this sample Table)

Data | Date

Hello     |  2010-07-1 15:11:11

World   | 2010-07-1 11:01:01

Hi there  | 2010-07-02 11:36:11

I need to find out their position number according to the Date when they were written into the Database,

i.e. which of them came first and which of them came second.

But I don't know if there is a component in cakePHP that can help me solve the question.

It is easy to list them out according to the Date and number each record manually when there are only a few records in the Database,but when the reocrds grow, it will be difficult for humans to do it this way:

Record 1: Hi there

Record 2: Hello

Record 3: World


In controller

$this->set('results', $this->MyTable->find('all', array('order'=>'date_field')));

In model

foreach($reuslts as $key=>$value){
  echo "Record ".$key.": ".$value['MyTable']['name']
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜