unemployment Posted February 15, 2011 Share Posted February 15, 2011 I get a php error...Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given $sql = "SELECT `pm_messages`.`conversation_id` FROM `pm_messages` GROUP BY `pm_messages`.`conversation_id` WHERE `pm_messages`.`conversation_id` = ${conversation['id']}"; $result = mysql_query($sql); $replies = mysql_fetch_assoc($result); Quote Link to comment Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 The WHERE clause should precede GROUP BY. Quote Link to comment Share on other sites More sharing options...
unemployment Posted February 15, 2011 Author Share Posted February 15, 2011 The WHERE clause should precede GROUP BY. Thank you. Quote Link to comment Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 Usually that error indicates the query is failing. To quickly check if it is you can temporarily change this line to: $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 For a good tutorial of how to appropriately handle errors & exceptions, check out: http://www.phpfreaks.com/blog/or-die-must-die Quote Link to comment Share on other sites More sharing options...
unemployment Posted February 15, 2011 Author Share Posted February 15, 2011 For a good tutorial of how to appropriately handle errors & exceptions, check out: http://www.phpfreaks.com/blog/or-die-must-die Thanks Maq. I'll start to read this now. FYI I tried the query below and it fails. $sql = "SELECT `pm_messages`.`conversation_id` AS `id` FROM `pm_messages` WHERE `pm_messages`.`conversation_id` = ${conversation['id']} GROUP BY `pm_messages`.`conversation_id` COUNT `pm_messages`.`conversation_id`"; $result = mysql_query($sql); $replies = mysql_fetch_assoc($result); echo $replies['id']; Quote Link to comment Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 Firstly, you have like 3 threads floating around with very similar questions. Please do not start duplicate topics, it is a huge waste of time. FYI I tried the query below and it fails. How does it fail? Did you append the or die() to see what the error was? Quote Link to comment Share on other sites More sharing options...
unemployment Posted February 15, 2011 Author Share Posted February 15, 2011 Firstly, you have like 3 threads floating around with very similar questions. Please do not start duplicate topics, it is a huge waste of time. FYI I tried the query below and it fails. How does it fail? Did you append the or die() to see what the error was? Sorry about the multiple threads. I've tried several variations of this to try and get this working. Error Message: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given Quote Link to comment Share on other sites More sharing options...
Maq Posted February 15, 2011 Share Posted February 15, 2011 You did not do what I said. What I said was to change this line to: $result = mysql_query($sql) or die(mysql_error()); The answer, again, is here: http://www.phpfreaks.com/forums/php-coding-help/total-unique-id%27s-with-php-and-mysql/msg1527874/#msg1527874 The order of your clauses are messed up. Read the manual for the correct order: http://dev.mysql.com/doc/refman/5.0/en/select.html Quote Link to comment 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.