我需要知道如何为网站制作评级脚本。我有一个表格,可以向MySQL提交 10 分的评分。您将如何获得从MySQL列中显示的平均评分?
--- 使用 PHP 和 MySQL
最好的方法是存储 2 列 - rate_count 和 rate_total。然后,当您获得新评级时,您只需发布如下更新:
update rating_table set rate_count = rate_count + 1, rate_total = rate_total + $rating where id = $id
然后得到你检索rate_count和rate_total的平均值。只要 rate_count > 0,rate_total/rate_count 会给你你的平均评分。