【问题标题】:How to get Max rating post in CakePHP如何在 CakePHP 中获得最大评分帖子
【发布时间】:2017-10-27 12:39:44
【问题描述】:

我是 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
    )
)

【问题讨论】:

  • 不清楚你在问什么。您想要评分最高的帖子吗?
  • 例如。 ORDER BY rating DESC, LIMIT 1

标签: php html mysql cakephp cakephp-2.3


【解决方案1】:

要获得评分最高的帖子,您只需按此字段排序并且只要求第一个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-03
    • 2022-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    相关资源
    最近更新 更多