Jocka Posted October 19, 2006 Share Posted October 19, 2006 What I'm trying to do is simply like forums. I have my topics and my replies. I want to bring the newest post to the top. I just for some reason have no clue where to start lol.I was thinking maybe somehow doing a while statement on the topics and running a while statement within that for the replies. After typing all that out thinking it would work, I was then missing some topics that were just made.I've coded (and helped code) 3 different forums now. I've had no problem with this before but for some reason my brain just isn't working now. I've lost all my old stuff and can't figure out what I did. Can somebody help please? Please don't make me study forums :P Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 19, 2006 Share Posted October 19, 2006 desc <<< descending.orasc <<< asending.examplehttp://www.1keydata.com/sql/sqlorderby.htmlgood luck Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 19, 2006 Author Share Posted October 19, 2006 Yea, I know that. But I then need to sort it by recent topics AND replies. I know theres probably some kind of sql code I can use to do this too. I was using a PHP way but I don't remember it. The problem, like i said, is it tends to only give the topic order when just doing DESC but when I use the while within the while statement, I get the topics in order but some topics just go missing. Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 19, 2006 Share Posted October 19, 2006 i'm not really sure what you're actually asking (some query samples/table structures/examples would help), but you can specify as many columns in the ORDER BY as you want:[code]ORDER BY reply_date DESC, topic_date DESC[/code]again, tough to tell what you're after. Quote Link to comment Share on other sites More sharing options...
trq Posted October 19, 2006 Share Posted October 19, 2006 The solution is quite simple, and doing it with while loops is totally inifficient. All you need do is create two timestamp fields (date_added, date_modified), when a topic is created, populate both these fields with the current date/time.Next, whenever a reply is added to a post, update the date_modified field to the current timestamp.Then... simply run your query and ORDER BY the date_modified field. Quote Link to comment Share on other sites More sharing options...
Jocka Posted October 19, 2006 Author Share Posted October 19, 2006 wow.. .. and for some reason I didn't think of that.. I'm feeling like a complete jackass right now HAHA.Thanx for the SQL help though akitchin! 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.