Jump to content


Photo

return SPECIFIC sql results


  • Please log in to reply
4 replies to this topic

#1 avenged

avenged
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 12 March 2006 - 02:55 AM

k, I would like to know how exactly I would go about selecting certain rows out of a mysql query. Example:

the query:

"SELECT * FROM pm WHERE reciever='$user_id'";

How would I sort through the results it returns to get only ones that contain the value of 1, and nothing else?


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 March 2006 - 03:02 AM

I don't understand your question. You have a query that will return ONLY rows where the field named reciever contains the value of $userid. So what would you like to see that's only equal to 1?
"SELECT * FROM pm WHERE reciever='$user_id' AND somethingelse = '1'";

Legend has it that reading the manual never killed anyone.
My site

#3 avenged

avenged
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 12 March 2006 - 03:07 AM

ok. I have written a function for my private messaging system that I have written. It's supposed to return the total number of PM's a user has in his inbox.

function getTotalPM($id)
{
    $pm_query = "SELECT * FROM pm WHERE reciever='$id'";
    echo mysql_num_rows(mysql_query($pm_query));
}

What I want to know is if I can limit the results that this function returns to ones that only have the value of 1(in this case, PM's that have not been read) so I can then make a new function(getNewPM()) to return the number of unread PM's the user has. How would I modify this function to return the intended results?

#4 avenged

avenged
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 12 March 2006 - 04:20 AM

anyone??

#5 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 08:29 AM

function getTotalPM($id)
{
    $pm_query = "SELECT * FROM pm WHERE reciever='$id' and read = 1";
    echo mysql_num_rows(mysql_query($pm_query));
}

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users