按ID和按日期排序 [英] Group by ID and Order by date
本文介绍了按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个主题)。
此代码不处理唯一ID(唯一主题),我该如何解决?
$ lastComments = $ this->评论 - > find('all' ,array('fields'=> array('Comment.news_id','Comment.date','Comment.content'),
'group'=> array('Comment.news_id'),
'order'=>数组('Comment.date DESC'))
);
此代码将返回唯一主题,但按日期排序不起作用:/
解决方案
$ this-> Comment-> find('first',array('order'= > array('Comment.id DESC')));
$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'))
);
The idea is to get latest comment from unique topics (1 comment - 1 topic).
This code doesn't handle unique ID's (unique topics), how Can I fix that?
Distinct doesn't work.
$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')));
这篇关于按ID和按日期排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文