I want to show some Calculated Values in CGridView, but it only shows ONE row in CGridView
The function:
public $Name;
public $ calculatedSum;
public function listSum()
{
$criteria = new CDbCriteria();
$criteria->select = 'Name as Name,'
. 'sum((wert1-wert2-wert3-wert4)*24) AS calculatedSum,'
return new CActiveDataProvider ( $this, array (
'criteria' => $criteria));
}
When I delete the AS calculatedSum
part of the query it shows all results, but with the AS calculatedSum
part it only shows one result in CGridView. But I need the AS calculatedSum
to show the calculated Field in the view.
Anybody have an idea for a solution ?
$criteria->select = 'Name as Name,'
. '((wert1-wert2-wert3-wert4)*24) AS calculatedSum,'
Don't use the sum function. That sums up all columns, and without group by (which also isn't needed) will always cause you to have just one row. All you need is simple arithmetic, as you have inside the parenthesis.