jonsjava Posted June 5, 2008 Share Posted June 5, 2008 != means NOT EQUAL TO. Which means that if recieved equals anything other than 0, it will return true. With recieved = 1, it would only return true if there was 1 message. I hope I didn't confuse you are all. And here I thought that recieved was a true/false statement, not a numerical representation of the quantity of messages they had. Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558388 Share on other sites More sharing options...
fanfavorite Posted June 5, 2008 Share Posted June 5, 2008 You could actually write is like this as well: <?php session_start(); include '../settings.php'; $user= get_username($_SESSION['user_id']); $query = "SELECT * FROM messages WHERE reciever = '$user'; $result = mysql_query($query); $f = mysql_fetch_array($result); echo "you have ".$f[recieved]." message(s)"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558389 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 ahh that makes sence ty ah you see i knew how to do that last way but i want to diplay it like this inbox or inbox(1) so not to clutter up the homepage ty guys Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558394 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 ok i found a slight error in my ways lol the thing is.. if a message is not read its 0 if its read its 1 so i need to gather all the 0's not the 1ns so what would i do here :S <? $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved != 0"; $result = mysql_query($query); $no_of_msgs = mysql_num_rows($result); if ($no_of_msgs != 0){ $data = mysql_fetch_assoc($result); echo "Inbox($no_of_msgs)"; } else{ print "Inbox"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558431 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0; Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558432 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 lol nope back to square 1 again sorry lol <? $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0"; $result = mysql_query($query); $no_of_msgs = mysql_num_rows($result); if ($no_of_msgs != 0){ $data = mysql_fetch_assoc($result); echo "Inbox($no_of_msgs)"; } else{ print "Inbox"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558514 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 <?php $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0"; $result = mysql_query($query); $no_of_msgs = mysql_num_rows($result); if ($no_of_msgs != 0){ $data = mysql_fetch_assoc($result); echo "Inbox($no_of_msgs)"; } else{ print "Inbox"; }?> That should work Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558519 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 lol nope i just get inbox when iv set it again to 2 new Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558524 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 Let me make sure I understand your DB: ---------------------------------------- | ID | message | reciever | recieved | ---------------------------------------- |int | varchar | varchar | tinyint | ---------------------------------------- |5 | 500 | 50 | 1 | ---------------------------------------- Something like that? And when a new message arrives, the field named 'recieved' is set to "0", right? Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558529 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 correct when a new message is created its at 0... when its read its set to 1 Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558536 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 I have no idea how changing != to = could have broke it. what the query is saying is: "Select everything from messages that belongs to this user, as log as it hasn't been read" Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558543 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 that what i was thinkin lol my query outputs SELECT * FROM messages WHERE reciever = 'Admin' AND recieved = 0 Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558548 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 a down-and-dirty test: <?php $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0"; $result = mysql_query($query); print "you have ".mysql_num_rows($result)." messages"; ?> if it says "0", then change your script to this: <?php $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = '0';"; $result = mysql_query($query); $no_of_msgs = mysql_num_rows($result); if ($no_of_msgs != 0){ $data = mysql_fetch_assoc($result); echo "Inbox($no_of_msgs)"; } else{ print "Inbox"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558553 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 wahooo that worked... how did you work it out... think its best to learn so then if it comes up again i can attack it myself lol Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558573 Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 It's not storing it as a numerical value, it's storing it as a varchar, which means that you need the " ' " to get it to work. If it were numerical, you would see it in the first query. Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558575 Share on other sites More sharing options...
runnerjp Posted June 5, 2008 Author Share Posted June 5, 2008 ahh yes makes sence.... thaks pal !! Quote Link to comment https://forums.phpfreaks.com/topic/108834-solved-counting-received-messages/page/2/#findComment-558590 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.