Recently Posted Query

Discussion in 'Databases' started by proph3t, Jul 16, 2006.

  1. #1
    I have a custom forum built and all is running well but I'm struggling with setting up one query. The relevant tables are:

    forum_threads
    forum_posts

    Posts go inside of threads and have the column `thread` to their parent thread. Both of these tables have the column `date`. How would I create a "Recent Threads" query that combines both of these tables. I would like the query to return the most recent threads while accounting for posts inside of them.

    Hopefully this is clear enough, thanks in advance.
     
    proph3t, Jul 16, 2006 IP
  2. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #2
    Are you looking to display to newest made thread, or the thread with the newest made post?
     
    smatts9, Jul 16, 2006 IP
  3. proph3t

    proph3t Guest

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm looking to combine those, the results should include newest made threads along with newest posts, but I will just display the thread where the post was made.
     
    proph3t, Jul 16, 2006 IP
  4. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #4
    I'd suggest adding a column, 'last_updated' in the table forum_threads, and in this column put the date of the last post. So when you create the thread at first just have it put the same value for 'date' in for 'last_updated'. Then when a new post for the specific thread is made have it update the forum_threads table column 'last_updated' to the date the post was made.

    Then you can just query the DB and list the threads by 'last_updated', and use LIMIT to tell how many threads to display.
     
    smatts9, Jul 16, 2006 IP
  5. proph3t

    proph3t Guest

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Wow, that was simple. Thank you very much.
     
    proph3t, Jul 17, 2006 IP