How to calculate average on star rating system?

后端 未结 2 1541
野趣味
野趣味 2021-01-03 03:48

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;
$sta         


        
2条回答
  •  醉梦人生
    2021-01-03 04:02

    You need to multiply the number of stars with the actual rating. Like

    $points_stars_2 = $stars_2 * 2  
    ...  
    $points_stars_5 = $stars_5 * 5 
    

    And then you add them all to one variable like in your code, and then divide it by $total_votes.

    Regards

提交回复
热议问题