SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: My database for a forum

  1. #1
    SitePoint Zealot applenerd's Avatar
    Join Date
    Dec 2005
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question My database for a forum

    Hey guys. I am most likely going to be building my own forum. I am wondering about how I should go about making my db. I will have one big db called forums. Then what should I do. Have a table made for each topic and then a big table with all the topics and the id of the table with the rest of posts for that topic? Or should I have one table with all of the posts and a "parent id" for which topic they are under. I am leaning towards a table for each topic but I would like some guidance here.

    thanks,
    axel

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,463
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    one table for each topic would be a mistake

    i personally would use only one table for all topics/threads, posts, and replies
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot applenerd's Avatar
    Join Date
    Dec 2005
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so not lots of tables. So here would be the table data:
    id | description | thread_content | poster | views | parent_id | type etc...
    The parent id would be the id of the original post and views would only be kept for the kind of type (either topic or reply) topic.

    sound good?
    axel

  4. #4
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,463
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    that's how i'd do it, except i wouldn't need views or type to tell me whether it was a topic or a reply -- a reply has a parent_id value, a thread starter or topic doesn't, its parent_id is null
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot applenerd's Avatar
    Join Date
    Dec 2005
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I'll give that a try!

    axel

Bookmarks

Posting Permissions

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