Jump to content

Archived

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

unkn0wndj

MySQL PHP issue

Recommended Posts

Alright I was wanting to pull information from a MySQL database. Heres the code im using

[code]$mnum = mysql_query("select * from messages where msg_recieverid='$_SESSION[usrid]'");

$mnumber = mysql_num_rows($mnum);[/code]

Alright so I was wondering.. I need to have the msg_recieverid still included because that's what tells it to pull only from their ID, but what I really need to know is msg_read='U' because that says that the message is unread and thats the whole purpose of it. So how can I make a command that lets me pull the number of msg_read='U' that someone has for their msg_recieverid..

Please help

Share this post


Link to post
Share on other sites
Assuming you just need the count, and not the actual messages, then the following should suffice:

[code]SELECT COUNT(*) AS cnt FROM messages WHERE msg_recieverid='$_SESSION[usrid]' AND msg_read ='U'[/code]

Then pull back the single row containing the count with mysql_fetch_array().

Share this post


Link to post
Share on other sites
[!--quoteo(post=358465:date=Mar 25 2006, 11:51 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Mar 25 2006, 11:51 PM) [snapback]358465[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Assuming you just need the count, and not the actual messages, then the following should suffice:

[code]SELECT COUNT(*) AS cnt FROM messages WHERE msg_recieverid='$_SESSION[usrid]' AND msg_read ='U'[/code]

Then pull back the single row containing the count with mysql_fetch_array().
[/quote]

Sorry i dont understand what you mean by

" Then pull back the single row containing the count with mysql_fetch_array()."

Could you please copy what the code needs to contain for that to work :)

oh btw the recieverid is a number

Share this post


Link to post
Share on other sites
Since it's just going to be one value anyway, you can use the following:

[code]$count = mysql_result($query, 0, 0); [/code]

Share this post


Link to post
Share on other sites
mysql_result(): supplied argument is not a valid MySQL result resource in /home/vhosts/www.nowiby.com/templates/topnav.php on line 20

Share this post


Link to post
Share on other sites
[!--quoteo(post=358605:date=Mar 26 2006, 02:06 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 26 2006, 02:06 PM) [snapback]358605[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try

$count = mysql_result($mnum, 0, 0);
[/quote]


Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/vhosts/www.nowiby.com/templates/topnav.php on line 20

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.