Page 1 of 1

Forum table design

Posted: Fri Dec 14, 2007 9:02 pm
by Chalks
I'm working on building my first forum. I'm very excited about it because, well... I'm a hopeless nerd. :D


I'm trying to decide how I should create the tables containing all posts. I've got four ideas:
1. One huge table that has all the forum names, threads, and replies in it.

2. Two tables, one with all forums and threads in it, then a second table with all the replies to the threads within it.

3. X tables, one containing all forums, then a new table for each new thread which contains the threads and replies.

4. one table for each forum containing all threads and replies to those threads within.


I think #4 is the most efficient, but I'm not sure. I would appreciate some input before I got so far into coding that a table design change would screw up everything. :)


Thanks

Posted: Fri Dec 14, 2007 10:15 pm
by John Cartwright
3 or 4 tables depending whether you want to support categories or not. Off the top of my head it would go something like

forum_categories (depending if you want to use categories or now like this forum does)
- id
- name
- order

forum_threads
- id
- category_id
- is_sticky
- is_annoucement
- post_id (contains the id of the original post)

forum_posts
- id
- thread_id
- user_id
- text_id

forum_text
- id
- date
- title
- content

forum_posts and forum_text could probably be combined if you want to simplify the design, however for normalization purposes I would keep the data separate.