On Wed, January 30, 2008 12:58 am, Dax Solomon Umaming wrote: > Hi; > > 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: > > // Results > Individual Daily Consumption > //AccountNo : Consumption > 4146121002: 1.42 > 4146111002: 0.29 > 4146113002: 1.38 > 4146110002: 0.33 > 4146112002: 0.00 > 4146118002: 9.96 > == MORE == > > // Code that generated the results > while ($row6 = mysql_fetch_assoc($queryconsumerresults)) { > // Show Consumer AccountNo and their Consumption > echo $row6['AccountNo'] . ": " . sprintf("%1.2f", > (((($row6['Reading'] + > $row6['KwHrAdjustment']) - ($row6['Reading1'] + > $row6['KwHrAdjustment1'])) / > $noofdays) * $row6['Multiplier'])) . "<br />"; > } > > I've tried getting the sum() from the MySQL table, but Multiplier is > either at > 1 or 2 or 2.5 and the only way I can get an accurate total consumption > is > getting the sum from the results. You should be able to use: sum( (Reading + KwHrAdjustment - Reading1 + KwHrAdjustment1) / $noofdays * Multiplier) from MySQL in another query... But if you are already iterating through the results anyway, it's probably just as easy to do: $sum = 0; while ($row6 = mysql_fetch_assoc(...)){ $consumption = $row6['Reading'] + ...; $sum += $consumption; } echo "Total: $sum<hr />\n"; > 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. > > -- > Dax Solomon Umaming > http://knightlust.com/ > GPG: 0x715C3547 > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php