Answer the question
In order to leave comments, you need to log in
Table schema, how to organize rating with pros/cons?
It is necessary to make a rating of posts / comments, as on Habré.
I mean the pros and cons and the fact that you can't gouge more than once.
How to organize table schema in MySQL? Now the rating is stored in the rating field of the entry itself, but this way the visitor can vote more than once.
Answer the question
In order to leave comments, you need to log in
Interim table posts_users_rel with the structure: id int, post_id int, user_id int
When a visitor votes, a record is added to the table containing the id of the post for which the visitor votes and the id of the visitor.
The verification will be very simple.
You can also insert a visitor's rating into the same table, minusanul (-1) or plusanul (+1) he, then the total rating of the post will simply be calculated by the sum of the ratings in this field.
my
article table contains the avg_rate field - we write the average value of the votes in it
rating table - article id, qty - the number of votes, sum - the sum of the votes
when voting for the article, we:
1. add 1 to the qty field in the rating table
2 add an estimate to the sum field sum
3. calculate the average and write it to the table of articles
Why write? And to make it a little easier to work with articles later.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question