Let’s say I have 3 MySQL table. A song db called songs that has a song’s artist, album, etc. The main thing here is lastfm_id which is the song’s UNIQUE id.
Then there’s a list (with 10 spots, like top 10 songs). People can create lists by adding songs to their list and rank them 1 to 10. This db doesn’t really needed to be touched for this.
Finally, we have song_listed which is the songs people picked to be put into a list. Here ti is:

As you can see, the song_id in song_listed is the same as lastfm_id in the table songs. Now since there is only one list in the database, there is 10 songs. If there 3 lists created, there would be 30 rows in song_listed each with their own rank of 1-10.
How would I get the average rank in the song_listed of each song in a list?
Imagine there’s a page that shows a list via list.php?id=11912 or something like that.
You would then get the songs from song_listed where list_id was 11912.
Here’s what I got so far:
$listSongs = 0;
while ($listSongs <= 9) {
// Don't worry, I did a query and $songID[x] works.
$songID = $songID[$listSongs]; // ex: 12949331
$getAvgRank = mysql_query("") or die(mysql_error());
}
EDIT
if you want one request by song_id (which is not a great idea, but)
CAUTION : this is just the “logical” solution. Use parametrized queries (and read Ben’ comment on mysql_* functions).