Issue
I want the SUM of data available in the particular column using the Yii query. Here is the code:
$resource_cnt = Resources::model()->findAll(array(
'select'=>'prj_id, SUM(amount) as amt',
'condition'=>'prj_id=:prj_id',
'params'=>array(':prj_id'=>$_POST['Resources']['prj_id']))
);
I tried using the query above. But it did not get the SUM of amt
variable.
Solution
The "correct" thing to do it Yii, if you want it nicely do in the model, is to
declare a property in Resources
called amt
.
Then it should work with your query. Yii only populates those atrributes from a select query, which it can find in the model.
class Resources.... {
public $amt;
...
public yourFunction() {
$resource_cnt = Resources::model()->findAll(array(
'select'=>'prj_id, SUM(amount) as amt',
'condition'=>'prj_id=:prj_id',
'params'=>array(':prj_id'=>$_POST['Resources']['prj_id']))
);
echo $resource_cnt->amt;
}
...
}
Answered By - Asped
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.