View Full Version : Comment Engine suggestions/help

03-07-2009, 12:16 AM

I'm creating a racing-simulation based team website where I would like to have the ability for people to register and leave comments across a wide variety of page types.

Such as:
-- bio page (commenter can leave a note on the team members page)
-- News Article (leave a comment on the news article in question)
-- Vehicle setup (leave a comment under the setup and whether or not it helped, etc, etc.)

In my mind, I can see this happening two ways...I'm just not sure which way to go about it and am looking for a little creative direction:

1) Use a 'users' MySQL table, and create a 'comments' table for each type of comment I would like saved (bio comments, setup comments, etc) and when the user leaves a comment, it would just use predefined SQL queries to insert the data into the appropriate table.

2) Use a 'users' table, but have only a single 'comments' table to store ALL the comments, only using different field types to filter the comments to their appropriate place.

My problem with Option 2 is that I'm not sure how to make it so the PHP/SQL combination knows where the comments are being posted from, and how to pull them out appropriately in the end.

That way something like:

would pull the comments specific to them from a uniform comments table. Use hidden form values?

Or is Option 1 the best route so all the data can be hardcoded rather than based on possible hidden values?

Suggestions / Opinions will be very helpful. Thank you!
-- Ryan

03-07-2009, 01:01 AM
I would go with Option 3 - your 'users' table and single 'comments' table idea. However, instead of the comments table using different 'comments' fields for the different types of comments, a single 'comments' field and an additional 'type' field to indicate the type of comment. You could then filter the comments based on 'type'.

03-07-2009, 01:59 AM
Ok, so basically it would be something like:


-type (ENUM? 'bio','news','setup',etc)

And then in the actual comment SQL area, just predetermine the type via a variable in the query string?

03-07-2009, 02:02 AM
Looks fine.

The 'type' field can be an ENUM or you could also go with a TINYINT, and assign the comment types to values. ie:

1 = bio
2 = news
3 = setup

This would allow you to add types at any time without needing to update your db.

And then in the actual comment SQL area, just predetermine the type via a variable in the query string?
That would work. There may be other ways as well, depending on how your code is structured.

03-07-2009, 02:17 AM
Thank you, much appreciated. :)

I'll fiddle around with it some, it won't be anything super high-tech. I'll just need to protect from any sort of SQL injection.

03-07-2009, 02:25 AM
you're welcome. good luck with it.