For now I sort all the threads in my forum using this:
SELECT * FROM board ORDER BY id DESC LIMIT 50
This shows the newest thread created on the top, but how would I go about showing the thread that has the most recent reply but also showing a new thread on the top?
Example:
- This is a new thread
- This is a old thread
- This is a old thread
To:
- This is a old thread with a new reply
- this is a new thread without replies
- This is a old thread
This is the reply code if thats any help:
$sql="INSERT INTO reply (id, name, subject, maintext, ip, date, img)
VALUES
('$idid','$name','$subject','$maintext','$encoded','$date','$image_name')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_query("UPDATE board SET replycount = replycount + 1 WHERE id = $idid");
If I understand your question, you want to sort by both recent replies and newest threads. I can’t give you exact syntax without more information about your tables, but your query might look something like this:
This uses the
GREATESTfunction to sort each row by eitherreplyDateTime, orcreationDateTime… whichever is more recent.EDIT:
With your reply information in a separate table, your query could use a left join, and then select the most recent reply for each post in board… and then use
GREATESTto select either the creation date of the post, or the most recent reply of the post.