Re: mysql query with SUM

From: Date: Wed, 17 Oct 2001 19:38:01 +0000
Subject: Re: mysql query with SUM
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71384@lists.php.net to get a copy of this message
Try something like: $query = "SELECT SUM(count) as sumtotal FROM counter WHERE type = 'cars'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row[sumtotal]; Rick > I have a database table with whole numbers in a column. Im trying to > get the script to add up these numbers by using 'sum' in the sql query. > It works correctly from mysql command line. > For some reason I cannot echo it out using php. What am I doing wrong.... > > > ----------------------------------------------------------------- > > <?php > /* Attempt to corrctly syncronize the counter table */ > include("db.php"); > mysql_connect($dbhost, $dbuname, $dbpass); > mysql_select_db($dbname); > echo "TEST<br>"; > $query = "SELECT SUM(count) FROM counter WHERE type = 'cars'"; > $result = mysql_query($query); > $c = mysql_result($result, 0); > echo "$c"; > ?> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#71384) next »