Jacbey Posted May 5, 2011 Share Posted May 5, 2011 Hi Guys, I have been having problems with a piece of PHP and mysql. I was wondering if you could help me out? The error is = Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /customers/klueless.net/klueless.net/httpd.www/daisysite/home.php on line 120 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /customers/klueless.net/klueless.net/httpd.www/daisysite/home.php on line 122 And this is the code which goes with these errors = $msgquery = "SELECT * FROM spotty_messages WHERE (id_receiver = '" . $userid . "') AND read = '0'"; $messageres = mysql_query($msgquery); $messrow = mysql_fetch_array($messageres); $messagecount = mysql_num_rows($messageres); Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/ Share on other sites More sharing options...
smsmarketeers Posted May 5, 2011 Share Posted May 5, 2011 Remove the parenthesis in the query: $query = mysql_query("SELECT * FROM spotty_messages WHERE id_receiver = '" . $userid . "' AND read = '0'"); $result = mysql_fetch_array($query); $rows = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211181 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 or $query = mysql_query("SELECT * FROM spotty_messages WHERE id_receiver = '{$userid}' AND read = '0'"); $result = mysql_fetch_array($query); $rows = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211184 Share on other sites More sharing options...
mikosiko Posted May 5, 2011 Share Posted May 5, 2011 @jacbey: error means that your query is failing, a good reason for that is the usage of a mysql reserved word read is one of them.... 2 options: a) change the name of the column (the best long term solution) or b) enclose it in backtics in this way `read` Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211188 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 good catch mikosiko, i didn't even notice that :-\ Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211193 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 and if that column's datatype is int you wont need the single quotes around the zero EDIT or the id_receiver one Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211194 Share on other sites More sharing options...
Jacbey Posted May 6, 2011 Author Share Posted May 6, 2011 Thanks guys. I'll try it out and let you know if it works. Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211209 Share on other sites More sharing options...
Jacbey Posted May 6, 2011 Author Share Posted May 6, 2011 @jacbey: error means that your query is failing, a good reason for that is the usage of a mysql reserved word read is one of them.... 2 options: a) change the name of the column (the best long term solution) or b) enclose it in backtics in this way `read` Thank you, I'll change the column name. How do you get backtics? Because I don't see a key on my keyboard for that. Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211212 Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 depends on keyboard on my mac its right of the lefthand shift key, on my pc its to the left of 1 ```````````` theres some i given you for free, please copy and paste Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211216 Share on other sites More sharing options...
Jacbey Posted May 6, 2011 Author Share Posted May 6, 2011 depends on keyboard on my mac its right of the lefthand shift key, on my pc its to the left of 1 ```````````` theres some i given you for free, please copy and paste Found it on my keyboard, thank you Quote Link to comment https://forums.phpfreaks.com/topic/235649-mysql-query/#findComment-1211231 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.