xstevey_bx Posted February 24, 2009 Share Posted February 24, 2009 <?php function newmessages() { $query = "SELECT COUNT(id) FROM messages WHERE to_id='$_SESSION[uid]'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $num_rows = $row['COUNT(id)']; echo 'Message Inbox (' . $num_rows .')'; } ?> The above statement works, However when I introduce an AND statement it breaks, even though the column name is correct... I dont know whats going on? <?php function newmessages() { $query = "SELECT COUNT(id) FROM messages WHERE to_id='$_SESSION[uid]' AND read='0'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $num_rows = $row['COUNT(id)']; echo 'Message Inbox (' . $num_rows .')'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146706-solved-count-not-working/ Share on other sites More sharing options...
JonnoTheDev Posted February 24, 2009 Share Posted February 24, 2009 Can you print the mysql error using mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/146706-solved-count-not-working/#findComment-770236 Share on other sites More sharing options...
xstevey_bx Posted February 24, 2009 Author Share Posted February 24, 2009 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read='0'' at line 1 Lol I could have told you that haha I know it had something to do with the AND part of the statement Quote Link to comment https://forums.phpfreaks.com/topic/146706-solved-count-not-working/#findComment-770243 Share on other sites More sharing options...
JonnoTheDev Posted February 24, 2009 Share Posted February 24, 2009 READ is a mysql reserved word. You cannot use it as a field name. http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/146706-solved-count-not-working/#findComment-770249 Share on other sites More sharing options...
xstevey_bx Posted February 24, 2009 Author Share Posted February 24, 2009 Bingo!! thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/146706-solved-count-not-working/#findComment-770251 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.