Hello In need help with count my posts in begin of forum categories list
SELECT COUNT(id) FROM posts a INNER JOIN topics b ON a.tid = b.id WHERE b.fid=$fid this is the old code,
Can I do this count in my forum model by relations or better do it in controller and how it looks in yii style?
thanks!
Page 1 of 1
Count With Join
#2
Posted 09 February 2013 - 03:04 PM
Dear Friend
Let us consider an example.
Author and Posts.
Author has many posts.
relation.
Now we listing aurhor names.
we can also the number of posts written by him like following.
We can also finetune a bit.
We want to know how many posts the author written related to YII.
Regards.
Let us consider an example.
Author and Posts.
Author has many posts.
relation.
public function relations()
{
return array(
'posts' => array(self::HAS_MANY, 'Post', 'a_id'),
);
}
Now we listing aurhor names.
we can also the number of posts written by him like following.
$author:Author::model()->findByPk($id); echo count($author->posts);
We can also finetune a bit.
We want to know how many posts the author written related to YII.
$author=Author::model()->findByPk($id); echo count($author->posts(array( 'condition'=>'title LIKE "%yii%"', )));
Regards.
Share this topic:
Page 1 of 1

Help












