First off, the query that I'm using is this:
PHP Code:
$query = "SELECT threads.id, threads.subject, threads.timestamp, categories.name, started.id AS starterid, started.username AS starter, lastreply.id AS lastreplyid, lastreply.username AS lastreply FROM `threads` LEFT JOIN `users` AS started ON started.id = threads.started LEFT JOIN `users` AS lastreply ON lastreply.id = threads.last_reply LEFT JOIN `categories` ON categories.id = threads.category LIMIT 0,30";
What that does is get all the needed information from 4 tables to show the threads on the index.php page.
Im assuming most/all of you know how a forum generally works; and what I'd like to do is order the threads by according to a linked value from another table.
Example:
Code:
+----+-------------------------+---------+----------+------------+
| id | subject | started | category | timestamp |
+----+-------------------------+---------+----------+------------+
| 1 | First Thread in Forum. | 1 | 1 | 1184270342 |
| 2 | Second Thread in Forum. | 2 | 2 | 1184337553 |
| 3 | Third Thread in Forum. | 1 | 2 | 1184690571 |
+----+-------------------------+---------+----------+------------+
Thats the threads table. and the posts are linked to the threads via the id. I'd like to take that and make a sql query much like this.
SELECT * FROM threads SORT BY posts.timestamp;
I know you cant do that, but thats as close as i can think.
|