Jump to content

need help ..


Jocka

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.