Averages

From: Date: Mon, 07 Sep 2009 01:28:15 +0000
Subject: Averages
Groups: php.db 
Request: Send a blank email to php-db+get-46474@lists.php.net to get a copy of this message
I am making a voting / rating application. I am working on the following query: SELECT cartoons.reference, cartoons.cartoon_title, cartoons.date_added, IFNULL(AVG(ratings.rating), 0) as 'average_rating' FROM cartoons INNER JOIN ratings ON cartoons.reference = ratings.content_reference WHERE ratings.content_type =3 ORDER BY cartoons.cartoon_title ASC I only get 1 result because IFNULL(AVG(ratings.rating), 0) is giving me the result of all the ratings every submitted where ratings.content_type =3. The '3' is symbolic of cartoons. What I am wanting to do is show on the web page a list of all the cartoons and their current rating. In my ratings table I have a content_type column to know what area of the web site is being voted of (3 for cartoons) and I have content_reference which referrs to the auto_increment value of cartoons.reference. How do I be more specific with the AVG so I will get a rating for each cartoon in the table? Ron

« previous php.db (#46474) next »