Greetings. Now, the times if half past five in the morning and I've been pulling my toes out for this a couple of hours and lets just say my brain aint geting better since I get close to something workable, then it turns into shreads.
Anyways:
I got one TblForumPosts which contains Posts and Topics
ID , int
forumID -Tells what forum the post belongs to, int
UserID -What user made this post', int
timest -timestamp (php: time() ), bigint
subject - Yep, just a subject, varc 25
message - the message, text
SubID -Tells me what ID it is connected to
Now to further explain how this hangs togheter:
If "SubID" is 0 it is a topic
If "SubID" is >0 it is connected to an ID with a SubID=0(Thus its a reply to a topic)
Now what I'am trying to get is the five topics under forumID=1 that have been posted in most recently, oh yes, TblUser.ID=TblForumPosts.UserID so that TblUser.nickname as nickname π
I'am thinking I should have made a TblTopics and TblPosts tabel instead, but even If that would have taken less time I dont give up easily because I want to get this one to work.
Currently I get thoose values from my sql listing 5 topics:
ID - The Topic ID
replies - The number of replies to the Topic
forumID- the forum the topic belongs to, this one is hard to fail on
Subject - The subject of the Topic
timest - The Timestamp... for the original Topic not the last one with matching SubID, thus displaying Topic Creation date and not last post date
Have I managed to explain it somewhat? The sql statment I had been working on which I managed to erase looked along thoose linesπIam realy tired now)
SELECT t.ID, COUNT(p.SubID) as replies, t.forumID, t.subject, u.nickname, p.timest
FROM TblForumPosts as t, TblForumPosts as p, TblUser as u
WHERE t.forumID=1 AND t.SubID=0 AND u.ID=t.UserID AND p.SubID=t.ID
GROUP BY t.ID
ORDER BY p.timest
LIMIT 0,5
Any help to try to fix this up would be appreciated :-)
/C
Edit:
I just tried with the above sql and well... I just tried it on a forum(2) that had only a topic and no subids, it didnt give me back much >_<