ranking based on calculations
Posted: Mon Aug 28, 2006 9:51 pm
Hey all,
I'm trying to rank football players based on some calculations ($row['ffr_points']). I've got it working, but with one small problem...it doesn't take into account those players with the same point totals. For those players that have the same pt total, I would like to assign them the same rank #. Some pointers to get me in the right direction would be appreciated.
This is what I have so far:
I'm trying to rank football players based on some calculations ($row['ffr_points']). I've got it working, but with one small problem...it doesn't take into account those players with the same point totals. For those players that have the same pt total, I would like to assign them the same rank #. Some pointers to get me in the right direction would be appreciated.
This is what I have so far:
Code: Select all
while ($row = mysql_fetch_array($result))
{
$row['ffr_points'] = (($row['sumpassyd'] * 0.05) + ($row['sumpasstd'] * 4) + ($row['sumqbint'] * -2) + ($row['sumrecyd'] * 0.1) + ($row['sumrushyd'] * 0.1) + ($row['sumrecatt'] * 1) + ($row['sumtotaltd'] * 6));
$rows[] = $row;
}
usort($rows, 'sort_rows_by_points');
$playerRank = 0;
echo "<table align=\"center\">";
foreach($rows as $row)
{
$playerRank++;
print "<tr><td>$playerRank. <img src=\"../images/NFL/logos/$row[nflteam_icon]\"> $row[fname] $row[lname]</td></tr>";
}
echo "</table>";
function sort_rows_by_points($a, $b)
{
if($a['ffr_points'] < $b['ffr_points']) return 1;
if($a['ffr_points'] > $b['ffr_points']) return -1;
return 0;
}
?>