Jump to content

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);

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.