Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Database design question

Database design question
Thread Tools
Junior Member
Join Date: Jun 2002
Location: Springfield
Status: Offline
Reply With Quote
Jun 3, 2005, 08:23 AM
 
Hi, I have a basic grasp on SQL and database design, but I would like some help brainstorming...

I'd like to set up a database backend for an online forum, I guess somewhat similar to Slashdot's design. I'd like to have the following type of comment design:
  • Comment #1
  • Comment #2
    • Comment #2.1
    • Comment #2.2
      • Comment #2.2.1
      • Comment #2.2.2
      • Comment #2.2.3
  • Comment #3
    • Comment #3.1
  • Comment #4
  • Comment #5

Basically I'd like to design a database that allows not only comments on the original post, but comments also on other comments.

I'd greatly appreciate any ideas on how to design this (I'll be using MySQL for my db), or if you could point me in a general direction.

Thanks a lot,
disco_stu
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 3, 2005, 08:57 AM
 
It looks like a pretty normal one-to-many relationship here, the standard solution for which is to put some field like parent_id that refers to the comment being commented on.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Zim
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Jun 3, 2005, 10:17 AM
 
To expand on what Chuck said.. as a programmer I kept thinking how to make linked-lists in DB... but just store all comments as equal items, with their fields being

- parent_id
- text
- who
- when
- ip
- timestamp

and then for each comment you print, search for all comments that have it as their parent_id, and print those comments.. again searching for each of those for any comments that have this "sub" comment as their parent... etc.

Still drives me batty sometimes

Mike
     
Junior Member
Join Date: Jun 2002
Location: Springfield
Status: Offline
Reply With Quote
Jun 3, 2005, 10:58 AM
 
Originally Posted by Zim
*SNIP*...then for each comment you print, search for all comments that have it as their parent_id, and print those comments.. again searching for each of those for any comments that have this "sub" comment as their parent... etc.
Thanks for the replies, guys. This was along the lines of what I was thinking, but I wasn't sure how efficient it was to recursively query the database. Worst case, there could be a TON of calls to the database ( O( n log n )? Arg, I can't believe I'm actually using something from my Algorithms classes! ), so I was just curious if there was another way to design the db so that I wouldn't have to do so many potential queries.

Again, thanks for the input.
disco_stu
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 3, 2005, 02:26 PM
 
If you want to load them all at once, you could also include a thread attribute and then sort them into parent-child relationships based on their parent_id yourself.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2