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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.