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);
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.
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.
5 Stars: 80-100. 4 Stars: 60-80. 3 Stars: 40-60. 2 Stars: 20-40.
You can find your test score as a percentage by dividing your score by the total number of points, then multiplying by 100.
Needs to be like this:
($stars_1 + $stars_2 * 2 + $stars_3 * 3 + $stars_4 * 4 + $stars_5 * 5) / $total_votes;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With