Jump to content

Archived

This topic is now archived and is closed to further replies.

Jocka

need help ..

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

Share this post


Link to post
Share on other sites
desc <<< descending.

or

asc <<< asending.


example

http://www.1keydata.com/sql/sqlorderby.html

good luck

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


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

Share this post


Link to post
Share on other sites

×

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.