␡
- Getting Started
- Creating the Non-Ajax Version
- Adding Ajax
- Retrieving Ratings
- Final Thoughts
Like this article? We recommend
Retrieving Ratings
Retrieving Ratings
Once you have a few ratings in the system, to retrieve the average rating for an item, use this query (replacing X with the actual item ID):
SELECT ROUND(AVG(rating), 1) AS average FROM ratings WHERE item_id=X
That query will return a number rounded to one decimal point. You could run this query within the rating.php script in order to show the item’s average rating.