Jump to content

[SOLVED] Total Up Money


stormx

Recommended Posts

Hello,

 

I need a little assistance with PHP and Maths, I want to be able to total up digits with two decimal places, I tried writing my own script, and here it is below:

 

<?php $result = mysql_query("SELECT * FROM invoices WHERE userid='4'" );
$num_rows = mysql_num_rows($result);

echo "$num_rows Invoices\n"; ?>  $<?php
while($history = mysql_fetch_array($result)) {
$total += $history['total'];
echo $total;
}
?>

 

I get the following output: 3 Invoices $6.9513.940.85

 

The total of invoices is correct, but the amount of them isn't. This was what is under userid 4 in the database for total:

 

6.95

6.95

26.95

 

I just want to plus them all together, but my code is seeming to give more than it should, please help me :)

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/149335-solved-total-up-money/
Share on other sites

I would do something like this:

 

<?php $result = mysql_query("SELECT * FROM invoices WHERE userid='4'" );
$num_rows = mysql_num_rows($result);

echo "$num_rows Invoices\n"; ?>  $<?php
for($i = 0; $i <= $num_rows; $i++) {
$total += $history['total'];
return $total;
}
echo $total;
?>

 

That should do it, but not tested. :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.