Using Display list to calculate and show list result

ChrisDK 23 Jan, 2016
I am trying to show calculated profit from income and expenses, but for some reason CC only calculates and show part of the database rows. I put it in a custom list:

Header code:

<?php
$totalexp=0;
$totalinc=0;
$totaltotal=0;
?>


Body code:

<?php
$totalinc=$totalinc+$row['totalinc']['Amount_inc'];
$totalexp=$totalexp+$row['totalinc']['Amount_exp'];
?>


Footer code:

<?php
echo "<b>";
echo "Total income";
echo $totalinc;
echo "</b>";
echo "<b>";
echo "Total Expenses";
echo $totalexp;
echo "</b>";
$totaltotal=$totalinc-$totalexp;
echo "Total profit";
echo $totaltotal;
echo "</b>";
?>



The rows Amount_inc and Amount_exp is coming from same tabble jos_account_exp but it seems i can only get onw row value calculated at a time, and the loop simply stops after about 30 rows.

What do i do wrong?
GreyHead 24 Jan, 2016
Hi ChrisDK,

This may be a scope problem. I suspect that the variables you set in the header don't exist when the body and footer code runs. That was true for CFV4. What worked then was to define them as global variables in the header, then repeat the global definition before using them in the body or footer.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger