Re: Sum of results

From: Date: Wed, 30 Jan 2008 07:12:36 +0000
Subject: Re: Sum of results
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-268307@lists.php.net to get a copy of this message
On Jan 30, 2008 1:58 AM, Dax Solomon Umaming <knightlust@gmail.com> wrote: > I've tried Googling this out but failed to search for an answer to this, so > I'm posting to this list. I'd like to know if there's a way to get the sum > this results: you can simply sum them as you print the report $sum = 0.0; while ($row6 = mysql_fetch_assoc($queryconsumerresults)) { $curVal = ((($row6['Reading'] + $row6['KwHrAdjustment']) - ($row6['Reading1'] + $row6['KwHrAdjustment1'])) / $noofdays) * $row6['Multiplier'])); // Show Consumer AccountNo and their Consumption echo $row6['AccountNo'] . ": " . sprintf("%1.2f", ( $curVal . "<br />"; // add curVal to sum $sum += $curVal; } > Is there a way I can place this code on an array? I've tried using > $indcons = array( sprintf("%1.2f", (((($row6['Reading'] + $row6 > ['KwHrAdjustment']) - ($row6['Reading1'] + > $row6['KwHrAdjustment1'])) / > $noofdays) * $row6['Multiplier']))) but I've obviously failed. array() creates an array, what youve done on this line is created an array with one element, which will be the last value of $row6 from the while loop that precedes it. since the last value returned from mysql_fetch_assoc() is false (thats what terminates the while loop), im guessing $indcons contains false as its only value. if you want to place these values in an array as you iterate over them, add this inside the while loop: $indcons[] = $curVal; -nathan

« previous php.general (#268307) next »