Page 1 of 1

MySQL SUM() question

Posted: Wed Mar 10, 2004 8:32 pm
by Illusionist
Hey i have a select statement like:

"SELECT *, SUM(calls) FROM tablename"

but... will it work? I mean i try using mysql_fetch_row and _fetch but always get errors... If this can be done this way, can someone show me how i would go about getting the value of SUM(calls)??
Thanks!

Posted: Wed Mar 10, 2004 8:35 pm
by markl999

Code: Select all

$sql = "SELECT SUM(calls) AS total FROM tablename";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
echo 'Total : '.$row['total'];
You can't select *, SUM(calls) as you'de be trying to select all rows, and a SUM ... where would it put the SUM :o

Posted: Wed Mar 10, 2004 8:45 pm
by Illusionist
lol, alright! thansk for clearing that up for me! I was started to thinkt aht i wasn't going to be able to do that. But ok! Thanks for the example!