Jump to content

how to echo sum(column) with php?


shams

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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.