I want to use a rate system in my app , well I know how to implement RatingBar
but I need to know the way I can calculate rating after each rate
For example user 1 give 5 starts but 2 other users gives 3 , 4 starts, so what is the result in this case and how to calculate it ? there is a formula of calculation for this issue ?
Asked
Active
Viewed 574 times
-1

Amine Choukri
- 398
- 2
- 12
2 Answers
0
yes, you have to show the average rating
the formula is (sum of all ratings)/(count of total rating)
example 4 user give rating 1,2,3,5 respectively.
then your formula be like
(1+2+3+5)/4
answer will be 2.75

Yogesh Choudhary Paliyal
- 604
- 1
- 8
- 23
-
but in my table user there is 1 column of rating so i think i should calculate rating after each rate ? – Amine Choukri Jan 10 '18 at 13:16
-
no you have to put a query and code to calculate the average rating. – Yogesh Choudhary Paliyal Jan 10 '18 at 13:17
-
but how ?? for example the first user gived 5 stars i will store in the column 'rating' the value of 5 stars , the second user gived 2 stars and here i should update the column rating to get the new rating .. well for this example there is 2 users but in the real time i can't konw how much users even if i create a new table with id user1,id_user2,rate that's it ?? – Amine Choukri Jan 10 '18 at 13:22
-
you have to keep all the ratings with user id. create 2 colums only user_id & user_rating. – Yogesh Choudhary Paliyal Jan 10 '18 at 13:24
0
If you have separate SQL tables for User and Ratings as tblUser
and tblRatings
respectively.
SELECT username, AVG(stars) AS average_rating
FROM tblUser
INNER JOIN tblRatings USING(mUserId)
GROUP BY mUserId
ORDER BY average_rating DESC, title;
Give your feedback if it helped of not. Happy to help more.

Er. Kaushik Kajavadara
- 1,657
- 2
- 16
- 37
-
-
if it helped then you can upvote and accept answer. thanks. – Er. Kaushik Kajavadara Jan 10 '18 at 13:33