我有一个包含字段Comment
的表名id, userid, content, posteddate
。
如何在此表中找到用户的最新评论(即id = 10
)?
答案 0 :(得分:2)
$Criteria = new CDbCriteria();
$Criteria->condition = "id = 10";
$Criteria->order = "posteddate desc";
$Comment = Comment::model()->find($Criteria);
答案 1 :(得分:1)
$model = Comment::model();
$attributes = ['userid' => 10];
$condition = ['order' => 'posteddate DESC', 'limit' => 1];
$result = $model->findByAttributes($attributes, $condition);