Jump to content


Unable to sum MySQL columns

  • Please log in to reply
1 reply to this topic

#1 acemiller6

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 27 August 2003 - 05:33 PM

From the MySQL prompt I can run the sum function no problem.

SELECT sum(apples) FROM kitchen;

and this will total the number of apples in the \"apples\" column of the kitchen db. That is working for me no problem. However, when I try to do that from my php code, its not working.

$temp = mysql_query(\"SELECT sum(apples) FROM kitchen\", $db);
echo \"Total apples: \". $temp;

It prints out to my browser:

Total apples: Resource ID #3

I know the database is open and it works because if I just try and look at one entry into the database with a select statement it works. So what I am doing wrong? Any help would be much appreciated.

"The poorest person in the world is the one for whom no one prays."

#2 effigy

  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 August 2003 - 05:38 PM

queries return resource id\'s which point to arrays. you then need to fetch the elements and loop through them. there are examples on the php site or tutorials here. this is a topic i just replied to, take note of how the information is retrieved:


Regexp | Unicode Article | Letter Database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users