Yii Count Records by attribute Example
Assume that we have a model with two columns, they are id and account_name
$datas = Account::model()->findAll();
echo CJSON::encode($datas);
[{"id":"1","account_name":"New Tea"},{"id":"3","account_name":"Travel"},{"id":"4","account_name":"Pettycash"},{"id":"13","account_name":"Travel"}]Assume that we have a model with two columns, they are id and account_name
$datas = Account::model()->findAll();
echo CJSON::encode($datas);
The above line shows the values in the model.
we want to count rows by specific acount_name.
line are as follows,
$data = Account::model()->findAllByAttributes(array(
'account_name'=> 'Travel',
));
echo count($data);
//output is 2
No comments:
Post a Comment