Hey everyone, I am trying to make a top 10 script for my site. I am having problems getting it working. I have a database that has a table for ratings. That list each rating someone gives it, then it list the item it goes with. I need to AVG the ratings then I need to get the top 10, and match the rating id number with the id in the items table so it can pull the resat of the info about the item. I am having trouble getting this to work here is what I have.
<table cellpadding=5 cellspacing=0 width="100%">
<?PHP
$querytutrate = "SELECT AVG(rating) as num, item_id as id FROM ratings WHERE item_type='tutorial' ORDER BY AVG(rating) DESC LIMIT 10";
$tutrate = mysql_query($querytutrate);
while ($tutrate) {
$id = $tutrate['id'];
$querytutinfo = "SELECT * FROM tutorials WHERE tutorial_id='$id'";
$tutinfo = mysql_fetch_array(mysql_query($querytutinfo));
$rate = round($tutrate[num],2);
?>
<tr>
<td><a href="index.php?id=<?PHP echo $tutinfo['tutorial_id']; ?>"><?PHP echo $tutinfo['tutorial_title']; ?></a> <?PHP echo $rating; ?></td>
</tr>
<?PHP
}
?>
</table>
If anyone can help me get this script working, i would really appreciate it.