Reputation: 51
I want to add a column that is the sum of the val_max column in the database
function controller
function admin_affiche() {
$this->Part->recursive = 1;
$parts = $this->Part->find('all', array(
));
$totalvals = $this->Part->Market->find('first', array(
array('fields' => array('sum(Market.val_max) AS valtotal'))));
$this->set('valtotal', $totalvals);
$this->set('parts', $parts);
}
view
<td class="tg-031e"><?php $totalvals[0]['valtotal'] ?></td>
the error is Undefined variable: totalvals
pass variavle to view
Upvotes: 0
Views: 138
Reputation: 223
Use $valtotal
in the view, not $totalvals
.
You are passing $valtotal
with this code $this->set('valtotal', $totalvals);
If you do echo pr($valtotal);
in your view, you will print the array.
Upvotes: 1
Reputation: 3807
I would suggest debug()
on the following to see what it is passing to your view, if debug = 2
is set. Else just use print_r
.
<?php print_r($valtotal); ?>
You just have to keep in mind that the first parameter in set()
is the variable that is passed to the view.
And in your case the variable passed is not $totalvals
but $valtotal
.
Upvotes: 0