Jump to content


Photo

MySQL PHP issue


  • Please log in to reply
8 replies to this topic

#1 unkn0wndj

unkn0wndj
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 March 2006 - 04:25 AM

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

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

$mnumber = mysql_num_rows($mnum);

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


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 March 2006 - 04:51 AM

Assuming you just need the count, and not the actual messages, then the following should suffice:

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

Then pull back the single row containing the count with mysql_fetch_array().
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 unkn0wndj

unkn0wndj
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 March 2006 - 05:23 AM

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

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

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

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 March 2006 - 07:27 AM

Since it's just going to be one value anyway, you can use the following:

$count = mysql_result($query, 0, 0);

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 unkn0wndj

unkn0wndj
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 March 2006 - 02:53 PM

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

#6 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 26 March 2006 - 03:00 PM

That happens when there is a MySQL error. Echo mysql_error() to see what it was.

#7 unkn0wndj

unkn0wndj
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 March 2006 - 06:58 PM

Doesnt say anything maybe my command is wrong ;\

#8 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 26 March 2006 - 07:06 PM

Try

$count = mysql_result($mnum, 0, 0);

#9 unkn0wndj

unkn0wndj
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 26 March 2006 - 09:38 PM

[!--quoteo(post=358605:date=Mar 26 2006, 02:06 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 26 2006, 02:06 PM) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users