RE: Re: [PHP] Addin a column of numbers not using MySQL
| From: | Jay Blanchard | Date: | Mon, 04 Aug 2003 17:59:07 +0000 |
| Subject: | RE: Re: [PHP] Addin a column of numbers not using MySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-158172@lists.php.net to get a copy of this message | ||
[snip]
I tried doing as you said and it returned 0. Is there another way to
add up the column?
[/snip]
$sql = "SELECT foo FROM table WHERE you have conditions ";
if(!($result = mysql_query($sql, $connection))){
print("MySQL reports: " . mysql_error() . "\n");
exit();
}
while($row = mysql_fetch_object($result)){
$total = $total + $row->foo; //each time through add the new amount
to the last amount
}
echo"$total\n";
HTH!