Page 1 of 1

ranking based on calculations

Posted: Mon Aug 28, 2006 9:51 pm
by esiason14
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:

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;
} 
?>

Posted: Mon Aug 28, 2006 9:59 pm
by feyd
What do you mean by "assign them the same rank"? The code is doing that.

Posted: Mon Aug 28, 2006 10:10 pm
by esiason14
feyd wrote:What do you mean by "assign them the same rank"? The code is doing that.
For example, these players have the same point total:

Code: Select all

62. Kevin Johnson with 30.3 points
63. Wayne Chrebet with 30.3 points
....but they are assigned different ranks (#62 and #63). I would like it to assign them the same rank (ie #62 as above) if they have the same point total

Posted: Mon Aug 28, 2006 10:20 pm
by feyd
Add some analysis logic to your foreach. Compare the calculation of the previous iteration to the current iteration.

Posted: Mon Aug 28, 2006 10:24 pm
by esiason14
Ok, let me give it a go and see if I can get it.