Php 平均评级脚本

Php 平均评级脚本,php,mysql,rating,Php,Mysql,Rating,我需要知道如何使一个网站的评级脚本。我有一个表单,它向MySQL提交了十分之一的评分。您如何从MySQL列中获得要显示的平均评级 ---将PHP与MySQL结合使用,最好的方法是存储两列——rate\u count和rate\u total。然后,当您获得新评级时,您只需发布如下更新: update rating_table set rate_count = rate_count + 1, rate_total = rate_total + $rating where id = $id 然后获

我需要知道如何使一个网站的评级脚本。我有一个表单,它向MySQL提交了十分之一的评分。您如何从MySQL列中获得要显示的平均评级


---将PHP与MySQL结合使用,最好的方法是存储两列——rate\u count和rate\u total。然后,当您获得新评级时,您只需发布如下更新:

update rating_table set rate_count = rate_count + 1, rate_total = rate_total + $rating where id = $id

然后获取平均值,检索rate_count和rate_total。只要rate\u count>0,rate\u total/rate\u count将为您提供平均评分。

看看这篇文章和代码