CakePHP:按ID和按日期排序 [英] CakePHP: Group by ID and Order by date
本文介绍了CakePHP:按ID和按日期排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$lastComments = $this->Comment->find('all', array('fields' => array('Comment.news_id', 'Comment.date', 'Comment.content'),
'group' => array('Comment.news_id, Comment.date'),
'order' => array('Comment.date DESC'))
);
这个想法是从唯一主题获得最新评论 1个主题)。
The idea is to get latest comment from unique topics (1 comment - 1 topic).
此代码不处理唯一ID(唯一主题),如何解决此问题?
This code doesn't handle unique ID's (unique topics), how Can I fix that?
区分不起作用。
$lastComments = $this->Comment->find('all', array('fields' => array('Comment.news_id', 'Comment.date', 'Comment.content'),
'group' => array('Comment.news_id'),
'order' => array('Comment.date DESC'))
);
此代码将返回唯一主题,但按日期排序不起作用:/
This code will return unique topics but order by date doesn't work :/
推荐答案
$this->Comment->find('first', array('order'=>array('Comment.id DESC')));
这篇关于CakePHP:按ID和按日期排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文