bululu Posted November 1, 2013 Share Posted November 1, 2013 Hi PHP Frieks, I have a problem that I wish you guys will solve (thanks in advance). I am pulling data from mysql (the Payment Column) and want to do running totals using PHP in column called Runnng Totals. As can be seen we have I prefer a PHP solution to the running totals as opposed to doing te totals in a MyQL query. ID Payment Running Totals 1 250 250 2 300 550 5 220 770 7 100 870 I have not yet come up with any code worthy posting as I am still fiddling with some code, and will post my efforts as soon I can come up with something sensible. Any help will be deeply appreciated. Link to comment https://forums.phpfreaks.com/topic/283510-php-running-totals/ Share on other sites More sharing options...
Ch0cu3r Posted November 1, 2013 Share Posted November 1, 2013 As you output the Payment value you add it to a $total variable $total += $row['Payment']; // add current payment to total and then echo the $total Example $result = msyql_query('SELECT id, Payment FROM payment_table'); $total = 0; // init total to zero while($row = mysql_fetch_assoc($result)) { $total += $row['Payment']; echo $row['id'] . ' - ' . $row['Payment'] . ' - ' . $total . '<br />'; } Link to comment https://forums.phpfreaks.com/topic/283510-php-running-totals/#findComment-1456508 Share on other sites More sharing options...
bululu Posted November 1, 2013 Author Share Posted November 1, 2013 @Ch0cu3r, you are the Genius! have tested it and It works like you coded it to and like I wanted it to! Thanks very much! Link to comment https://forums.phpfreaks.com/topic/283510-php-running-totals/#findComment-1456547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.