How to calculate average on star rating system?

后端 未结 2 1562
野趣味
野趣味 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:09

    Needs to be like this:

    ($stars_1 + $stars_2 * 2 + $stars_3 * 3 + $stars_4 * 4 + $stars_5 * 5) / $total_votes;
    

提交回复
热议问题