Well, if the thread_id
you're retrieving is correct, and the subject
column on the forum_threads
table contains the subject you're expecting, then there is a problem in your display level code rather than your query. (Since you're pulling thread_id
from the same row as t.subject
, if one is correct as you expect, the other should be, too.)
Besides that, and this is slightly off topic, I'd caution you against using constructs such as WHERE forums.id != 9 AND forums.id > 12
. Instead, you should have a column in the database for disabled
, and query against that. Otherwise you have an unmaintainable mess.
In response to the comments, try adding this block of SQL to your JOIN
clauses:
INNER JOIN (SELECT t2.forum_id as forum_id, MAX(lastpost) as lastpost
FROM forum_threads t2
GROUP BY t2.forum_id) as latest_post_per_forum
ON latest_post_per_forum.forum_id = t.forum_id
and this to your WHERE
clause:
AND t.lastpost = latest_post_per_forum.lastpost
Unfortunately I don't have a convenient MySQL instance at this time to test my syntax, but the gist should be obvious: pull the last post ID out on a per-forum basis and then compare each thread's last post ID to that.