justAnoob Posted June 5, 2009 Share Posted June 5, 2009 I have a table in mysql with a colum called 'status'.....The only thing that can go in the column is the word 'NEW', which is placed there when a member gets a new message. I am using the following code to get the number of new messages that a user has but it is not working. I tried using a var_dump to see what is going on and all i get is this... string(6) "timcin" int(0) ... Any ideas why it is not giving me the number of rows that I have. Is is something to do with the way that I have the word 'NEW' in the databae? <?php include "connection.php"; $userid = $_SESSION['id']; $sql=mysql_query('SELECT * FROM member_messages WHERE status = "NEW" and user_id = "$userid"'); $num_rows = mysql_num_rows($sql); var_dump($userid, $num_rows); echo "You have " . $num_rows . " new message(s)."; mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/ Share on other sites More sharing options...
Alex Posted June 5, 2009 Share Posted June 5, 2009 $sql=mysql_query('SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"'); Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849700 Share on other sites More sharing options...
justAnoob Posted June 5, 2009 Author Share Posted June 5, 2009 string(6) "timcin" int(0) Still giving a 0 when I use var_dump. Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849701 Share on other sites More sharing options...
btherl Posted June 5, 2009 Share Posted June 5, 2009 It's a good idea to put your query in a variable, print the variable and then run your query. That way you can see exactly what it is you are running. $query='SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"'; print "About to run $query\n"; $sql = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849705 Share on other sites More sharing options...
joel24 Posted June 5, 2009 Share Posted June 5, 2009 and also check if your sql command is running correctly and if not show the error with the "or die(mysql.error())" after the query... $query='SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"'; print "About to run $query\n"; $sql = mysql_query($query) or die(mysql.error()); Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849709 Share on other sites More sharing options...
justAnoob Posted June 5, 2009 Author Share Posted June 5, 2009 About to run SELECT * FROM member_messages WHERE status = "NEW" and user_id ="admin" Okay,, that is what I get. Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849712 Share on other sites More sharing options...
btherl Posted June 5, 2009 Share Posted June 5, 2009 The query looks fine to me. So I suspect there's no matching rows in the database. In the database, do you have "NEW" capitalized? Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-849718 Share on other sites More sharing options...
justAnoob Posted June 6, 2009 Author Share Posted June 6, 2009 Yes,,, NEW is capitalized in the database..... No one can figure this out... What is going on?? <?php include "connection.php"; $userid = $_SESSION['id']; $flip='SELECT id FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"'; $flop = mysql_num_rows($flip); // this line if($flop >= 1) { echo "You have new messages."; } ?> Tried using 'id' instead of '*' but still get the same error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on commented line Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-850383 Share on other sites More sharing options...
justAnoob Posted June 6, 2009 Author Share Posted June 6, 2009 Hey I got it... Awesome,,, this was killing me... This works... I'm so happy. <?php include "connection.php"; $fluke = $_SESSION['id']; $flip = ("SELECT id FROM member_messages WHERE status = 'NEW' and sendto = '" . $fluke . "'"); $flop = mysql_query($flip); $freak = mysql_num_rows($flop); if(!$freak) echo ""; else echo "You have new messages."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-850397 Share on other sites More sharing options...
btherl Posted June 7, 2009 Share Posted June 7, 2009 Were you checking the wrong column? Quote Link to comment https://forums.phpfreaks.com/topic/161007-solved-quick-question/#findComment-850954 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.