lalnfl Posted August 4, 2010 Share Posted August 4, 2010 Okay I am making a forum and it is almost finished. The only thing is, I am stuck on how to get the most updated topics to appear at the top of the list. Like on every forum there is a new forum post that you havent visited yet. They are at the top of the list. How would I do that??? Quote Link to comment Share on other sites More sharing options...
DWilliams Posted August 4, 2010 Share Posted August 4, 2010 Do you have a field storing a timestamp for when a thread's last post was? If so you could just use an ORDER BY clause like this simplified example: SELECT threadname, author FROM threads WHERE board_id=2 ORDER BY last_post DESC The DESC makes it sort backwards (higher to lower instead of visa-versa). Since a more recent timestamp will be larger, the query results will be ordered by post time from newest to oldest, at which point you can loop and display as normal and they will be sorted. If you don't have a "last post" type field associated with your thread and only store the timestamp with the post itself you could probably do something involving a join but joins hurt my brain and I've been doing way too much repetitive work today to provide you with a clear example of that. Quote Link to comment Share on other sites More sharing options...
lalnfl Posted August 4, 2010 Author Share Posted August 4, 2010 After I posted this topic, I realized that I would just have to use the ORDER BY and the DESC. Thanks for the reply anyways! Quote Link to comment Share on other sites More sharing options...
lalnfl Posted August 4, 2010 Author Share Posted August 4, 2010 But I do have another question though! I want the forum to say the forum topic then right next to the forum topic I want it to say "new". Like it does here on the phpfreaks.com forums. Like if the user hasn't viewed it yet, it would say "new". How would I do something like that? Its probably very simple like the first questioned I asked, but I can't figure this one out. Any help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.