Re: mysql query with SUM

From: Date: Wed, 17 Oct 2001 19:55:22 +0000
Subject: Re: mysql query with SUM
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71385@lists.php.net to get a copy of this message
No dice. But why would the original query work in mysql command line and not php. In the php sql statement, if I take out the WHERE clause, I could get an output from the echo statement, but its not what I want. Im trying to narrow down the search with just column 'type' with entries 'cars'. Is there something else like a 'WHERE' clause that Im overlooking that could be used.... Richard Baskett wrote:
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 (#71385) next »