The schema of the tables, how to organize a rating with pros/cons?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
4 views
You need to make the rating of posts/comments, on habré.

Mean pros and cons that we cannot continue Golovan more than once.


How to organize the schema of the tables in MySQL? Now the rating is stored in the rating field from the record itself, but the visitor can vote more than once.
by | 4 views

2 Answers

0 like 0 dislike
Posts_users_rel intermediate table with the structure: id int, post_id int, user_id int
\r
In the vote of the visitor is added to the table entry that contains the id of the post for which visitor votes and the id of the visitor.
\r
Verification will be very simple.
\r
This table and the assessment of the visitor insert minusanul (-1) or put (+1), then the total rating of the post is simply calculated by the sum of the scores in this field.
by
0 like 0 dislike
I have done so
the table articles contains the field avg_rate — in it we write the mean value of the votes
ranking table — id articles qty — the number of votes divided by the sum of the votes
\r
when voting for the article, we:
1. add 1 to the qty field in the rating table
2. add the rating to the field sum sum
3. pisitive average and write it in the table of articles
\r
Why write? And then to be a little easier to work with your articles.
by

Related questions

0 like 0 dislike
6 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 6, 2019 by dima9595
110,608 questions
257,186 answers
0 comments
28,009 users