Jump to content
abinidi

Help With Php/mysql Display Issue

Recommended Posts

I'm trying to get MySQL to return a SUM of items in one of the columns in my database table, and convert that into a format that I can display in PHP.

 

Here is the code I'm using on my .php page:

 

>$queryDinnerNumber="SELECT SUM(dinner_number) FROM data WHERE dinner = 'yes'";

 

This works, because when I run the code on the SQL tab of PHPMYADMIN, I get a table that has one row and one column, with the resulting value in that cell.

 

However, how do I display that value on my webpage?

 

Here is the code I'm trying:

 

><?
$queryDinnerNumber="SELECT SUM(dinner_number) FROM data WHERE dinner = 'yes'";
$resultDinnerNumber=mysql_query($queryDinnerNumber);
echo $resultDinnerNumber; ?> people have been invited to the dinner.

 

However, on my page, I see the following:

 

Resource id #7 people have been invited to the dinner.

 

How do I convert the value from the results into something I can display on my web page?

Share this post


Link to post
Share on other sites

what you have returned is a resource, not actual data

 

you need to do something like this:

 

>$queryDinnerNumber="SELECT SUM(dinner_number) as total FROM data WHERE dinner = 'yes'";
$resultDinnerNumber=mysql_query($queryDinnerNumber);

while($row = mysql_fetch_array($resultDinnerNumber))
{
$actual_results[] = $row;
}

print_r($actual_results); // this will print out your results array so you can see the values!


echo $actual_results[0]['total'] .'people have been invited to the dinner.';

Share this post


Link to post
Share on other sites

Thank you. That was the piece I've been missing!!

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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...