Jump to content

Selecting highest rating from list of ratings?


starvinmarvin14

Recommended Posts

I have a table which holds each individual rating as a row. An example of some data would be:

 

picid  |  rating

 

12          2

43          3

12          4

36          7

43          9

 

I also have another table which holds image info and has a column with the id that matches picid on the first table. How would I find the average rating of each 'picid' to be displayed on a top rated page?

 

So it should output

 

picid  |  rating

 

36          7

43          6

12          3

 

So far I have...  $statement1 = "SELECT picid, SUM(rating) AS total FROM ratings GROUP BY picid ORDER by total";

 

Let me know if you need further clarification.

How would I call this query? I am using mysql_fetch_assoc and am getting an error.

 

Is there anything wrong with this code?

 

        $statement1 = "SELECT picid FROM ratings GROUP by picid ORDER by AVG(rating)";

        $row2 = mysql_fetch_assoc($statement1);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.