Reputation: 14876
I have a table name Comment
containing fields id, userid, content, posteddate
.
How could I find the most recent comment of user (i.e. id = 10
) in this table?
Upvotes: 0
Views: 39
Reputation: 437386
$model = Comment::model();
$attributes = ['userid' => 10];
$condition = ['order' => 'posteddate DESC', 'limit' => 1];
$result = $model->findByAttributes($attributes, $condition);
Upvotes: 1
Reputation: 3103
$Criteria = new CDbCriteria();
$Criteria->condition = "id = 10";
$Criteria->order = "posteddate desc";
$Comment = Comment::model()->find($Criteria);
Upvotes: 2