[eluser]Unknown[/eluser]
Hi there,
I have a table of financial transactions and would like to calculate a running total column. Currently I perform the calculation in the View but I know this isn't correct (I'm pretty new to MVC).
How do I move this code out of the view? Any help would be great. Thanks. Scott
Code:
<table>
<? $row = 0 ?>
<? $runningTotal = 0 ?>
<?php foreach($transactions_list as $transaction): ?>
<? if ($row == 0)
$balance = $transaction->amount;
else
$balance = ($transaction->amount + $runningTotal);
?>
<tr>
<td><?= $transaction->date ?></td>
<td><?= $transaction->memo ?></td>
<td><?= $transaction->amount ?></td>
<td><?= $balance ?></td>
</tr>
<? $runningTotal = $runningTotal + $transaction->amount ?>
<?php $row++ ?>
<?php endforeach ?>
</table>