mmarif4u Posted April 3, 2007 Share Posted April 3, 2007 Hi everyone. I have a PMS for my users within my site. I want to run a query that will detect that a specific user who are login to the site, has how many new messages... How to perfrom this query: Like: $sql = "select * from pms where to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $row = mysql_num_rows($result); Echo "You have $row new messages."; Any help will appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/ Share on other sites More sharing options...
trq Posted April 3, 2007 Share Posted April 3, 2007 I want to run a query that will detect that a specific user who are login to the site, has how many new messages... Pardon? Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220294 Share on other sites More sharing options...
fert Posted April 3, 2007 Share Posted April 3, 2007 $sql = "SELECT COUNT(*) as new FROM pms WHERE to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $row=mysql_fetch_array($result); $num=$row['num']; echo "you have {$num} new messages"; Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220296 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Author Share Posted April 3, 2007 @ thorpe PMS mean private messaging system just like the phpfreaks are using. When some some body have new message from other member, when he go to his inbox there a small line that "you have 2 new messages" @fert thanks for ur query i will try it. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220299 Share on other sites More sharing options...
pocobueno1388 Posted April 3, 2007 Share Posted April 3, 2007 Fert - Where did this come from? $num=$row['num']; I don't understand where you pulled $row['num'] from. <?php $sql = "select * from pms where to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $num = mysql_num_rows($result); if ($num > 0){ echo "You have $num new messages!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220300 Share on other sites More sharing options...
fert Posted April 3, 2007 Share Posted April 3, 2007 sorry I meant $sql = "SELECT COUNT(*) AS new FROM pms WHERE to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $row=mysql_fetch_array($result); $new=$row['new']; echo "you have {$new} new messages"; Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220301 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Author Share Posted April 3, 2007 @ pocobueno1388... Fert - Where did this come from? $num=$row['num']; I don't understand where you pulled $row['num'] from. <?php $sql = "select * from pms where to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $num = mysql_num_rows($result); if ($num > 0){ echo "You have $num new messages!"; } ?> Thanks pocobueno1388... So it means that ur query will echo if they new message if no new message then nothing to show to the user... OHHH Yeh also this, my mind is dull this time: if ($num > 0){ echo "You have $num new messages!"; }esle { echo "You have 0 messages!"; } I think this will work. Am i right @ fert Thanks fert for ur correction. I will try both, hope both will work. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220302 Share on other sites More sharing options...
pocobueno1388 Posted April 3, 2007 Share Posted April 3, 2007 Oh, I thought you just wanted to show <b>new</b> messages, take out this code: if ($num > 0){ echo "You have $num new messages!"; }esle { echo "You have 0 messages!"; } and this should be your final: <?php $sql = "select * from pms where to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $num = mysql_num_rows($result); echo "You have $num new messages!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220307 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Author Share Posted April 3, 2007 Oh, I thought you just wanted to show <b>new</b> messages, take out this code: if ($num > 0){ echo "You have $num new messages!"; }esle { echo "You have 0 messages!"; } and this should be your final: <?php $sql = "select * from pms where to_id = '$nruser1' AND opened ='no' "; $result = mysql_query($sql); $num = mysql_num_rows($result); echo "You have $num new messages!"; ?> I think ur final code is same to my 1st post query, which did not work. Am i right... Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220309 Share on other sites More sharing options...
pocobueno1388 Posted April 3, 2007 Share Posted April 3, 2007 Hmmm, I guess that is the same thing you did...I wonder why it isn't working. First of all, did any of the suggested methods work for you? If nothing has worked yet, try adding this to your query result: $num = mysql_num_rows($result)or die(mysql_error()); I couldn't think of a way it wouldn't work unless you just queried the database wrong. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220313 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Author Share Posted April 3, 2007 Yes u r right i also wondered, when it does not work bcoz i am not so bad in php. That query just return the total number of messages for that user who is looged in . For example if he has 5 messages that code will show him "You have 5 new messages". And that time he has no new msg in the db. Other: I did not test the other queries yet bcoz i am far from my pc. I will try that may be that will work. Ok i will post either it works or not. Thanks again for ur help. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220318 Share on other sites More sharing options...
mmarif4u Posted April 3, 2007 Author Share Posted April 3, 2007 Hi guys again That one which i make and the others one which u prople post, all works. I dont know why last nite it doesnot work.(which i make[now working]) Thanks again for ur time. Quote Link to comment https://forums.phpfreaks.com/topic/45369-solved-detect-new-messages-for-inbox/#findComment-220447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.