如何获得CakePHP中的Max评级

时间:2017-10-27 12:39:44

标签: php html mysql cakephp cakephp-2.3

我是PHP的新手,我不明白如何只获得具有最高评级的帖子

 $all= $this->Post ->find('all', array('conditions' => array('id'), 'recursive' => -1, 'limit' => 2));

我想只显示评分最高的帖子。

[0] => Array
(
    [Post ] => Array
    (
        [id] => 1
        [name] => Gramercy Tavern 
        [contact] => 
        [cuisine] => 
        [rslug] => gramercy-tavern
        [state] => NY
        [rating] => 2
        [created_date_time] => 2017-10-14 16:42:10
    )
)

1 个答案:

答案 0 :(得分:0)

要获得评分最高的帖子,您只需要按此字段订购,只需要第一个:

$post = $this->Post->find('first', array(
    'order' => array('rating' => 'desc')
));