Nah MySQL / Joins are easy with a bit of practice, although I believe there are some other methods not available in this mySQL version that would make this query much easier. The original query at the base of this one was much simpler, and I had to get my brother to help, but this one is much more complicated and I wrote it.. heh. Here is a documented version for all the hackers out there
\n
//select unique rows only (don't think that matters for the new posts marker...) from the forums
SELECT DISTINCT f_forums.id AS id FROM f_forums
//Get all the threads in the forum
INNER JOIN f_threads ON f_threads.forum = f_forums.id
//Get the row for the "read posts" table for this thread provided the user in the f_read table is the logged in user
LEFT OUTER JOIN f_read ON f_read.thread = f_threads.id AND f_read.name='$loggedin'
//Get special access stuff (to determine whether this person can view the forum) for this forum, again where the user is the logged in one
LEFT OUTER JOIN f_saccess ON f_forums.id = f_saccess.forum AND f_saccess.user='$loggedin'
//Check whether the user has the forum ignored, same as above really
LEFT OUTER JOIN f_ignore ON f_ignore.forum = f_forums.id AND f_ignore.user='$loggedin'
//Keep this row in if the current last post is later than the last read time, or the user hasn't viewed the thread at-all yet
WHERE (f_read.time < f_threads.time OR f_read.thread IS NULL)
// ( if the user has a status lower than the minimum access to the forum AND If the access type is 1 [the type for allowing access to special forums]) OR (the user has a status greater than the minimum or they are an admin)
AND ((f_saccess.type=1 AND f_forums.minstatview > $status) OR f_forums.minstatview <= $status OR $status = 2)
// (if they're not banned from the forum, OR there is no special access record for this user)
AND ((f_saccess.type != -1) OR f_saccess.type IS NULL)
// if they're no ignoring the forum
AND f_ignore.user IS NULL
//if the last post time for the thread is greater than the cut-off time for marking posts as read (or when they clicked the "mark all posts as read" button)
AND f_threads.time > $earliest
\n
Note that this is just for that red 'Posts' you see on the side of the menu, so don't think that by finding some little mistake I may have made in this query you can gain access to all sorts of forums, it checks in different way in the forums, which are much less complicated. heh.
Your Comments: