I’ve got a script that does team ranking for a fantasy basketball website.
The rules for ranking are:
1. Within a division, the teams are ordered from most to fewest wins.2. If two teams have the same number of wins, then the team with fewer losses is listed above the team with more losses.3. If two teams have the same number of wins and losses, the team with the most wins against teams within the division is rated above the team with fewer wins within the division.4. If two teams have the same number of wins and losses, and the same number of wins within the division, the team with the fewest losses within the division is listed above the team with more losses within the division.5. If two teams have the same number of wins and losses and the same number of wins and losses within the division, the team that was ranked higher in the previous season is listed above the team that was ranked lower in the previous season.
So, here is the function in question that attempted to follow this:
[code=php]function Ranking($tm_arr){
$t_list = array();
$t_rank = array();
$l=0;
foreach($tm_arr as $tm){
array_push($t_list, $tm);
$t_list[$l][‘Placed’] = false;
$l++;
}
$loop_halt=0;
while(count($t_rank) < count($t_list) && $loop_halt < count($t_list)){
$l=0;
while(($t_list[$l][‘Placed’])){
$l++;
}
$top = $t_list[$l];
$l2 = 0;
$pl_num = 0;
while($l2 < count($t_list)){
if(!($t_list[$l2][‘Placed’])){
if(
($t_list[$l2][‘Wins’] > $top[‘Wins’]) ||
(
($t_list[$l2][‘Wins’] == $top[‘Wins’]) &&
($t_list[$l2][‘Losses’] < $top[‘Losses’])
) ||
(
($t_list[$l2][‘Wins’] == $top[‘Wins’]) &&
($t_list[$l2][‘Losses’] == $top[‘Losses’]) &&
($t_list[$l2][‘D_Wins’] > $top[‘D_Wins’])
) ||
(
($t_list[$l2][‘Wins’] == $top[‘Wins’]) &&
($t_list[$l2][‘Losses’] == $top[‘Losses’]) &&
($t_list[$l2][‘D_Wins’] == $top[‘D_Wins’]) &&
($t_list[$l2][‘D_Losses’] > $top[‘D_Losses’])
) ||
(
($t_list[$l2][‘Wins’] == $top[‘Wins’]) &&
($t_list[$l2][‘Losses’] == $top[‘Losses’]) &&
($t_list[$l2][‘D_Wins’] == $top[‘D_Wins’]) &&
($t_list[$l2][‘D_Losses’] == $top[‘D_Losses’]) &&
($t_list[$l2][‘Last_Seas’] > $top[‘Last_Seas’])
)
){
$top = $t_list[$l2];
$pl_num = $l2;
}
}//*/
$l2++;
}
array_push($t_rank, $top);
$t_list[$pl_num][‘Placed’] = true;
$loop_halt++;
}
return $t_rank;
}
For the most part, this works, but I’m running into a glitch. The page is at [url]http://fba.furtopia.org/Games/ranking.php
The glitch is this: two teams are being repeated, which should not happen.
One is under Western Conference > Southwest, the other is under Eastern Conference > Northern.