zoran Posted August 25, 2009 Share Posted August 25, 2009 I am building a forum, and its nearly done. It was working well untill I tried to get the number of therads listed in each debate. So I included COUNT(threads.title) AS nothreads, into statement below. $result = mysql_query("SELECT debates.debateID, debates.title, posts.debateID, debates.lastuser, users.name, COUNT(threads.title) AS nothreads, MAX(posts.dateposted) AS latest FROM debates,threads,posts,users where threads.debateID=debate.debateID AND debates.debateID=posts.debateID AND users.name=debates.lastuser GROUP BY debates.title, ORDER BY latest DESC"); Server version: 5.1.37 And the warning message I got is : Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\greatedebate.com\debate.php on line 21 can you help, please Quote Link to comment https://forums.phpfreaks.com/topic/171773-solved-my-statement-gets/ Share on other sites More sharing options...
kickstart Posted August 25, 2009 Share Posted August 25, 2009 Hi Suspect there is an error in the SQL. Add an or die(mysql_error()); to the end of the mysql_query line to see what it is. Obvious one is the extra comma GROUP BY debates.title, ORDER BY latest DESC. I would also suggest that you use the ON syntax to join the tables together, and also that you have both posts.debateID and debates.debateID when they will have the same value. Also would suggest you group by an ID field rather than a title (inevitably on a forum there will be different threads with the same title). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171773-solved-my-statement-gets/#findComment-905769 Share on other sites More sharing options...
zoran Posted August 25, 2009 Author Share Posted August 25, 2009 That was spot on, got it working thanks Quote Link to comment https://forums.phpfreaks.com/topic/171773-solved-my-statement-gets/#findComment-905776 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.