Re: Sum Columns

From: Date: Sat, 26 Jan 2002 04:25:34 +0000
Subject: Re: Sum Columns
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16209@lists.php.net to get a copy of this message
On Saturday 26 January 2002 13:19, 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]. > > How can I get the sum displayed? Try: $result = mysql_query("SELECT sum(value) AS Total FROM pets",$db); $myrow = mysql_fetch_array($result); print "$myrow[Total]"; "Total" can be anything you want. You can use it to alias a column name: SELECT a_column_with_a_very_long_name AS short_name FROM ... -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* Lonely is a man without love. -- Englebert Humperdinck */

« previous php.db (#16209) next »