Average rating value counting

artyshare

New Member
I am working on a website, which has 10 star rating system. All ratings are stored in tbl_rating and have attributes:\[code\]idheadingdescriptionrating (number of stars, 1 to 10)shop_id (each rating belongs to a shop - my site is a catalog of shops)\[/code\]My question is, how is it the best way to count average rating for a shop (basicaly I only need to sum all ratings with particular shop_id and divide them by number of those ratings). Every shop has also column avg_rating, where I can store the value.Is there any way to tell MySql database to count this statistics every hour? Should I count it after every new submitted rating or even every time the shop attribute avg_rating is queried? Is there any way to tell the database to do this automatically or do I have to run these actions from PHP? I am using PHP, Yii framework and MySQL database.Thanks for any help.
 
Top