Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    15

    Question Database for forum

    Hello everyone,
    i'm writing my own forum, and now my database has a table for categories, a table for forums (each forum belongs to only one category), a table for members, a table for threads (each thread belongs to only one forum, and each thread has only on member as thread starter), and a table for posts (each post belongs to only one thread and has only one member as poster). Now the questions is:
    how "reply to another reply" posts should be organized in the database?
    Thnx

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Acute View Post
    how "reply to another reply" posts should be organized in the database?
    add a column to the posts table called in_reply_to

    for posts which start a thread, this column is NULL

    for posts that reply to another post, put the other post's key into this column as a foreign key
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    I'd be more inclined to use a thread/post model than a reverse linked list like r937 suggested. Create one entity for threads, one entity for posts, and a linking entity for threads and posts.

    My reaoning is that you almost always traverse from threads to posts, almost never from posts to threads. While r937's suggestion is technically correct, it is relatively inefficient to implement. My suggestion is a tiny bit more complicated in terms of the ERD, but it is a lot more efficient to code/implement.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Apr 2009
    Posts
    15

    More details

    can you plz describe your idea/method in more details? i'm new in db design so... thnx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •