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

Roger H. rogerharness at sbcglobal.net
Sun Feb 6 01:26:10 CST 2005


Hello good listers, i have a simple MySql/PHP database script, (with the
usual display/add/delete/edit records), that I'm trying to modify. All I'm
trying to do now is print a total of some of the columns at the end of my
table.

I have a basic:
$query ="select * from my_table order by $food";
$result =mysql_query($query);

then a while loop:

$food=$row[0];
$calories=$row[1];
$carbs=$row[2];
etc etc.

then print the rows.

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; 
but i can't figure out how to do both, and more importantly, how to utilize
this into my php/html.
I've been googling, and checking the mysql site, but i'm not bright enough
to get this on my own apparently. Anyone have any suggestions or tips?

As always, thanks in advance folks. Much appreciated!

-Roger Harness 



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.5 - Release Date: 2/3/2005
 


More information about the thelist mailing list