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] Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.