Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate average on star rating system?

Tags:

php

vote

I am developing a star rating system with 1-5 stars. In my database I am saving them like this:

$stars_1 = 1;
$stars_2 = 6;
$stars_3 = 3;
$stars_4 = 11;
$stars_5 = 22;

$total_votes = 43

When a user votes using for example 3 stars I update stars_3 with 1 and total_votes with 1. Then I need to calculate the average rating (stars).

I do it like this right now but I is not working (result seems wrong):

(($stars_1 + $stars_2 + $stars_3 + $stars_4 + $stars_4) / $total_votes);
like image 794
Jonathan Clark Avatar asked Mar 19 '12 10:03

Jonathan Clark


People also ask

How can I calculate average?

Average This is the arithmetic mean, and is calculated by adding a group of numbers and then dividing by the count of those numbers. For example, the average of 2, 3, 3, 5, 7, and 10 is 30 divided by 6, which is 5.

How do you find the average rating in Excel?

Use AutoSum to quickly find the average Click a cell below the column or to the right of the row of the numbers for which you want to find the average. On the HOME tab, click the arrow next to AutoSum > Average, and then press Enter.

What percentage is a 5 star rating?

5 Stars: 80-100. 4 Stars: 60-80. 3 Stars: 40-60. 2 Stars: 20-40.

How do I calculate percentage of rating?

You can find your test score as a percentage by dividing your score by the total number of points, then multiplying by 100.


1 Answers

Needs to be like this:

($stars_1 + $stars_2 * 2 + $stars_3 * 3 + $stars_4 * 4 + $stars_5 * 5) / $total_votes;
like image 164
McGarnagle Avatar answered Nov 03 '22 00:11

McGarnagle