Jump to content


Photo

need help ..


  • Please log in to reply
5 replies to this topic

#1 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 19 October 2006 - 01:03 AM

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 October 2006 - 01:11 AM

desc <<< descending.

or

asc <<< asending.


example

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

good luck
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 19 October 2006 - 01:38 AM

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.

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 19 October 2006 - 02:36 AM

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:

ORDER BY reply_date DESC, topic_date DESC

again, tough to tell what you're after.

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 19 October 2006 - 02:40 AM

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.

#6 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 19 October 2006 - 03:08 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users