Mainforum
- Subforums
-- Topics
--- Topic message + reply's
When you click on one of the subforums, you will get a list with all the topics in that subforum. They have to be sorted by date & time from the last post. My tables are as following:
TOPIC
subforum_id
topic_id
title
post
date
time
sticky
REPLY
subforum_id
topic_ud
post
date
time
I had the following query:
Code: Select all
SELECT *
FROM topic AS topic, reply AS reply
WHERE topic.forum_id = '$subforum_id' OR // not AND, because reply can be empty
reply.forum_id = '$subforum_id'
ORDER BY topic.sticky DESC, // first the sticky ones on top
topic.datum DESC, // then sorting dates (topic or reply, doesn't matter which one first)
reply.datum DESC,
topic.tijd DESC, // then sorting on times
reply.tijd DESC