How to calculate average on star rating system?

核能气质少年 提交于 2019-11-30 15:30:50

Needs to be like this:

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!