shams Posted May 9, 2006 Share Posted May 9, 2006 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] Link to comment https://forums.phpfreaks.com/topic/9403-how-to-echo-sumcolumn-with-php/ Share on other sites More sharing options...
obsidian Posted May 9, 2006 Share Posted May 9, 2006 [!--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] Link to comment https://forums.phpfreaks.com/topic/9403-how-to-echo-sumcolumn-with-php/#findComment-34635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.