Jump to content

Archived

This topic is now archived and is closed to further replies.

avenged

return SPECIFIC sql results

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?
[code]
"SELECT * FROM pm WHERE reciever='$user_id' AND somethingelse = '1'";[/code]

Share this post


Link to post
Share on other sites
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.

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

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?

Share this post


Link to post
Share on other sites
[code]
function getTotalPM($id)
{
    $pm_query = "SELECT * FROM pm WHERE reciever='$id' and read = 1";
    echo mysql_num_rows(mysql_query($pm_query));
}
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.