Jump to content


Photo

how to echo sum(column) with php?


  • Please log in to reply
1 reply to this topic

#1 shams

shams
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 09 May 2006 - 03:07 PM

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:

<?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);
?>


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 May 2006 - 03:11 PM

[!--quoteo(post=372625:date=May 9 2006, 11:07 AM:name=shams)--][div class=\'quotetop\']QUOTE(shams @ May 9 2006, 11:07 AM) View Post[/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:

<?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);
?>
[/quote]

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

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users