A simple "totalling" query to produce - can't get it right.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

A simple "totalling" query to produce - can't get it right.

Post by simonmlewis »

I am echoing a table of values, the one in question is $row->total.

There may be 5 or 105 rendered rows, and at the bottom I need a total of that variable.

ie:
5
10
25
total: 40.

I have ready about "+=" but can't get it to work.
There will be about 10 other 'sums' to do as well.
I've so far got this:

Code: Select all

<td>£$row->total</td>
<td>£$row->unpaidbills</td>
<td>$row->timespent</td>
<td>£$row->estimate</td>
<td>$row->currentpos<br/>";
$totalsum += $row->total;
echo "$totalsum</td>
</tr>
";
But cannot get anything to render in $totalsum.

Can anyone help please?

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: A simple "totalling" query to produce - can't get it right.

Post by pbs »

Bring that echo $totalsum out of the loop.
Post Reply