Re: Sum Columns
| From: | Paul DuBois | Date: | Sat, 26 Jan 2002 04:22:20 +0000 |
| Subject: | Re: Sum Columns | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16208@lists.php.net to get a copy of this message | ||
At 23:19 -0600 1/25/02, mike@wkla.com wrote:
Hello,
I've been experimenting with adding decimal columns. From the mysql docs I
got this SELECT sum(value) FROM pets;
So I did this $result = mysql_query("SELECT sum(value) FROM pets",$db);
$myrow = mysql_fetch_array($result);
print "$myrow[value]";
I also tried $myrow[sum].
You're selecting a column named "sum(value)" not "value" or "sum".
$myrow[0] should give you the value you're looking for. Or modify your
query to add a column alias, and use the alias name:
$result = mysql_query("SELECT sum(value) AS the_sum FROM pets",$db);
$myrow = mysql_fetch_array($result);
print "$myrow[the_sum]";
How can I get the sum displayed? Thanks in advance, Mike -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net