I'm using 3 tables, one with the films (film), one with the votes (seen) and one with users (who) which is not used.
They look like this:
film (filmID,filmName,filmYear etc.)
1,Spiderman,2002, etc.
2,Daredevil,2003, etc.
3,X-Men,2000, etc.
seen (seenID,sVote,sWho, etc.)
1,3,1, etc.
2,8,1, etc.
3,2,2, etc.
4,3,3, etc.
who (whoID,whoName etc.)
1,"Mike", etc.
2,"Jane", etc.
3,"John", etc.
Here's the php:
$SQL = "SELECT seen.sVote, film.filmID FROM film INNER JOIN seen ON (film.filmID = seen.sName)";
$SQLfilm = mysql_query($SQL) or die($SQL);
$SQLrows = mysql_num_rows($SQLfilm);
while ( $row = mysql_fetch_array($SQLfilm) ){
$i++;
$FilmVote[$row['filmID']] = $FilmVote[$row['filmID']] + $row['sVote'];
$FilmVoteNum[$row['filmID']]++;
}
for ($i = 1; $i <= $SQLrows; $i++) {
if($FilmVote[$i]){ // only process film that has votes
$AVG[$i] = number_format($FilmVote[$i]/$FilmVoteNum[$i],2);
print $AVG[$i]
}
}
Maybe there's a better way to do it?