如何计算星级评分系统的平均值? [英] How to calculate average on star rating system?

查看:672
本文介绍了如何计算星级评分系统的平均值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发1-5颗星的星级评分系统. 在我的数据库中,我这样保存它们:

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

当用户使用3星进行投票时,我将star_3更新为1,将total_votes更新为1. 然后,我需要计算平均评分(星标).

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);

推荐答案

需要像这样:

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

这篇关于如何计算星级评分系统的平均值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆