Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-06-2009, 11:16 PM   PM User | #1
PodiumAssault
New Coder

 
Join Date: Feb 2009
Location: Delaware
Posts: 11
Thanks: 7
Thanked 0 Times in 0 Posts
PodiumAssault is an unknown quantity at this point
Question Comment Engine suggestions/help

Hola,

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:
http://www.teamwebsite.com/setupgarage.php?id=16
and
http://www.teamwebsite.com/newsarticles.php?id=445

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
PodiumAssault is offline   Reply With Quote
Old 03-07-2009, 12:01 AM   PM User | #2
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
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'.
__________________
John
PappaJohn is offline   Reply With Quote
Old 03-07-2009, 12:59 AM   PM User | #3
PodiumAssault
New Coder

 
Join Date: Feb 2009
Location: Delaware
Posts: 11
Thanks: 7
Thanked 0 Times in 0 Posts
PodiumAssault is an unknown quantity at this point
Ok, so basically it would be something like:

USERS
-userID
-userName

COMMENTS
-commentID
-userID
-type (ENUM? 'bio','news','setup',etc)
-commentText

And then in the actual comment SQL area, just predetermine the type via a variable in the query string?
PodiumAssault is offline   Reply With Quote
Old 03-07-2009, 01:02 AM   PM User | #4
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
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.

Quote:
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.
__________________
John
PappaJohn is offline   Reply With Quote
Users who have thanked PappaJohn for this post:
PodiumAssault (03-07-2009)
Old 03-07-2009, 01:17 AM   PM User | #5
PodiumAssault
New Coder

 
Join Date: Feb 2009
Location: Delaware
Posts: 11
Thanks: 7
Thanked 0 Times in 0 Posts
PodiumAssault is an unknown quantity at this point
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.
PodiumAssault is offline   Reply With Quote
Old 03-07-2009, 01:25 AM   PM User | #6
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
you're welcome. good luck with it.
__________________
John
PappaJohn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting 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

Forum Jump


All times are GMT +1. The time now is 06:31 PM.


Advertisement
Log in to turn off these ads.