简体   繁体   中英

User Reviews: Implementation of Comments - What technologies to use?

I have set up a company intranet website built with PHP/MySQL and allow users to post reviews. After joining up on this website I have grown to like the "comment" function and would like to add that same functionality to allow users to "comment" directly to other users reviews.

Currently all reviews are stored in a single table in the DB.

1) Should I create another table to then store all the comments since there can be many comments per review?

2) Once I figure out where to store these values can the rest of this functionality be built out in PHP or will other programming need to also be introduced?

  1. Sounds like a good plan. You can have a table like Comments(commentID, reviewID, comment_body, ...) . You can then insert a new entry when adding a new comment, or select all comments with a given reviewID to display comments for a given review.
  2. Yes, you will almost certainly implement this in PHP (the same language you use in the rest of your application). You'll also have to edit some HTML, and maybe javascript as well.

Yes and yes.

Comments should be a seperate table, because they're comments, not reviews. They are two different things, therefore, they should not go in the same table.

Once you've created that table with the appropriate references to other tables, it's just a matter of constructing a query which pulls out all of the information you need (eg SELECT user.user_name, comment.comment_text, comment.post_time FROM comment, user WHERE comment.user_id=user.user_id AND comment.review_id = 123 , where 123 is the ID of the review you're getting comments for).

The exact layout for your comment table will depend on your specific needs, but as a minimum, you'll want to know which review it's a comment for, who posted it, when they posted it, and what they actually posted.

To insert comments, create a form on the page that displays the individual review, and when filled in, create an INSERT query which inserts into your comment table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM