开发者

How to make a fairly simple 5- star rating system?

I am making it so people may download songs on my site, and I want there to be a rating system with 5-stars too tell which is best, Can someone help? I would like it to be in database something like user_id, rating then the php sorts out the algorithim and wha开发者_C百科t not shows images/stars.


Please see following Code:
http://www.phptoys.com/e107_plugins/content/content.php?content.75 http://2008.gr0w.com/articles/code/php_5_star_rating_system_using_hreview/


Here's a nice tutorial that teaches you how to do this:

http://webtint.net/tutorials/5-star-rating-system-in-php-mysql-and-jquery/


Add to your song table two columns:

  • int hits
  • float rating

When user rates a song fetch it's rating and hits and just do:

rating = ( hits * rating + userRating ) / (hits + 1)
hits = hits + 1

When you display stars, parse that rating to integer and you will get number of not-grayed stars to display.


Write to database rating from 1 to 5 Than doing smth like this:

SELECT SUM(rating)/COUNT(rating) FROM rating WHERE rating_for_id = INT
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜