[thelist] add comments to a home-made blog

Joel D Canfield joel at spinhead.com
Mon Jun 14 08:38:33 CDT 2004

> So maybe i'd create a rambling_comments table. I could have; 
> comment_num (primary key?) entry_num (from my rambling table, 
> right?) comment comment_user comment_date
> does this make sense? and if so, im not sure how that 
> entry_num is even going to GET into my rambling_comments table!
> Anyways, i know i havent thought this through NEARLY enough, 
> and I was just wondering if anybody could point me in the 
> right direction for some tutorials etc, for doing this.

In reverse order: if you want to get a handle on database design, you
absolutely must read 'Database Design for Mere Mortals'

If you want to connect an individual entry to a number of comments, what
you're doing is already close.

<pseudo code>
select * from comments where rambling_id = 123

(don't really select *, list the fields, or the database police will
come for you)

Since you have a one to many relationship already, there's no need for a
third table to connect them. That generally becomes necessary when you
have a many to many relationship. For instance, if users could comment
on multiple ramblings, or multiple users could comment on the same
rambling (not realistic, of course.)

So, new ramblings will have a unique id, each user will have a unique
id, and each comment will have a unique id. To get all the info for a
particular rambling:

select r.rambling, r.rambling_date, u.user, u.user_info, c.comment,
ramblings as r
left join
comments as c
r.rambling_id = c.rambling_id
left join
users as u
c.user_id = u.user_id

As always, someone who does this every day for a living is welcome to
comment/correct the above :)


More information about the thelist mailing list