Jump to content


Adding numbers in row

  • Please log in to reply
1 reply to this topic

#1 Cannibal_Monkey

  • Members
  • PipPip
  • Member
  • 21 posts

Posted 28 September 2006 - 11:26 PM

I have a row C of several numbers. I want to add all the numbers of that row and create a new variable. I have this for that line of code "$e = mysql_query('SELECT SUM `c` FROM `b`');" If it's wrong what do I do? I've searched around and couldn't find the answer.

#2 HuggieBear

  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 11:30 PM

It's almost right:

$sql = "SELECT SUM(c) as total FROM tablename";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
echo "The total is {$row['total']}";

Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users