Jump to content

[SOLVED] my statement gets


zoran

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/171773-solved-my-statement-gets/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.