[thelist] mysql/php: using the sum() function...i think

Robert Gormley robert at pennyonthesidewalk.com
Sun Feb 6 01:45:44 CST 2005

mysql_result - 

$query = "SELECT SUM(calories) AS calories FROM my_table";
$result = mysql_query($query);

print(mysql_result($result, "calories"));

You need the AS ... to make mysql_result cleaner.


> Now I just want to be able to total up the calories and carbs 
> at the bottom.
> I can do this at the mysql command line with:
> select SUM(calories) from my_table; or
> select SUM(carbs) from my_table; 

More information about the thelist mailing list