Re: Sum of results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 30, 2008 1:58 AM, Dax Solomon Umaming <knightlust@xxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux