Reputation: 5
I have a product page which displays a user's comment, name and rating of the particular product. These values are stored in my data base as such "Id, name, comment, rating"
Now I find myself struggling if I want to store comments,name and rating from all product pages into one table as the output would display comments, name and ratings on every page which I don't want.
Am I correct in trying to pursue this one table theory? Or should I just go ahead and make a seperate table for each product page?
Upvotes: 0
Views: 52
Reputation: 10202
Your comments can go in a single table, you should however store the identifier of the product, so you can filter the comments. Example:
+------------+------------+------+-----------------+
| comment_id | product_id | name | comment |
+------------+------------+------+-----------------+
| 1 | 1 | john | Cool product! |
| 2 | 2 | jack | Don't like this |
| 3 | 1 | jack | Nice! |
...
Now if you want to display all comments for the product with id 1, you would execute this query:
SELECT * FROM `comments` WHERE `product_id` = 1
There you go! You have john's comment, and jacks comment which says "Nice!"
Upvotes: 1