Jump to content

Archived

This topic is now archived and is closed to further replies.

shams

how to echo sum(column) with php?

Recommended Posts

hi,
this is a mysql query to get sum of one colmn from mysql table, how i can print the result with php script, this is what i did but doesn't work:
[code]

<?php
$var = 'PZA';
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
mysql_query("SELECT SUM($var) FROM treatment");
echo SUM($Var);
?>
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=372625:date=May 9 2006, 11:07 AM:name=shams)--][div class=\'quotetop\']QUOTE(shams @ May 9 2006, 11:07 AM) [snapback]372625[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hi,
this is a mysql query to get sum of one colmn from mysql table, how i can print the result with php script, this is what i did but doesn't work:
[code]

<?php
$var = 'PZA';
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
mysql_query("SELECT SUM($var) FROM treatment");
echo SUM($Var);
?>
[/code]
[/quote]

try something like this:
[code]
$x = mysql_query("SELECT SUM($var) as tot FROM treatment");
$tot = mysql_result($x, 0, 'tot');
echo $tot;
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.