Hello,
I have 2 tables set out like this :
File Table
File ID
File Name
Voting Table
User ID
Vote Rank
File ID
Basically I want to display the top 5 ranked files. Below is what I started with when my head went flat and died (Then again could be because its 3:30am in the UK 😛).
$sql = "SELECT * from hr_files where active='Y' and category='sound'";
$result= mysql_query($sql);
if(!$result)
{
error('SQL',mysql_error());
}
$i=1;
while($row = mysql_fetch_array($result)){
$sql4 = "SELECT * from votes where file_id=".$row['id']."";
$result4= mysql_query($sql4);
if(!$result4)
{
error('SQL',mysql_error());
}
$votestotal=mysql_num_rows($result4);
if($votestotal!=0){
while($row3 = mysql_fetch_array($result4)){
$totalv=$row3['rank']+$totalv;
}
$rating=$totalv/$votestotal;
$totalv=0;
}
else
{$rating=0;}
$rating[$row['id']]=$rating;
sort($rating);
// WENT BLANK - Below was there already when the vote mark was in files table
if(strlen($row['title'])>22){
$addon="..";
}
else
{$addon="";}
echo "<font size='2'><span class='style9'>".$i.". </span><a href='download.php?id=".$row['id']."' target='content' class='style9''>".substr($row['title'],0,22).$addon."</a></font><br/>";
$i++;
}
if($i==1){
echo "<font size='2'><span class='style9'>There are no music files!</span></font>";
}
echo "<br/>";
Thanks in advance!
James