calculating ranks in php - loop?
Posted: Sun Sep 02, 2007 7:35 pm
Hey i have a script which isnt running properly. Its ment to calculate the new position of a team after a win has been reported.
heres the code
So if Team F plays a match and they originally has 100 points. From their win, they now (for example) have 198 points.
Previously, the ranking were as follows:
Rank 1: Team A had 220 points
Rank 2: Team B had 210 points
Rank 3: Team C had 200 points
Rank 4: Team D had 190 points
Rank 5: Team E had 180 points
Rank 6: Team F had 100 points
Rank 7: Team G had 90 points
Now:
Rank 1: Team A has 220 points
Rank 2: Team B has 210 points
Rank 3: Team C has 200 points
Rank 4: Team F has 198 points
Rank 5: Team D has 190 points
Rank 6: Team E has 180 points
Rank 7: Team G has 90 points
It stores there new rank as 4 in the database.
MY current script above wont work. It keeps giving wrong ranks . Can someonle look at this for me.
Regards
heres the code
Code: Select all
//FIND WINNERS NEW RANK
$totalranked=mysql_query("SELECT COUNT(*) FROM ladder_$ladder[id] WHERE rank > '0'");
$totalranked=mysql_fetch_array($totalranked);
$totalranked="$totalranked[0]";
$adjustranks="";
if($winner[rank] > 0){
if(($winner[rank] > $loser[rank]) && ($loser[rank] > 0)){
$middlerank=(($winner[rank] + $loser[rank]) - 0.5);
$new_winner_rank=round(($middlerank / 2) - 0.5);
$adjustranks=1;
}else{
$new_winner_rank="$winner[rank]";
}
}
else{
$new_winner_rank=($totalranked + 1);
$adjustranks=1;
}So if Team F plays a match and they originally has 100 points. From their win, they now (for example) have 198 points.
Previously, the ranking were as follows:
Rank 1: Team A had 220 points
Rank 2: Team B had 210 points
Rank 3: Team C had 200 points
Rank 4: Team D had 190 points
Rank 5: Team E had 180 points
Rank 6: Team F had 100 points
Rank 7: Team G had 90 points
Now:
Rank 1: Team A has 220 points
Rank 2: Team B has 210 points
Rank 3: Team C has 200 points
Rank 4: Team F has 198 points
Rank 5: Team D has 190 points
Rank 6: Team E has 180 points
Rank 7: Team G has 90 points
It stores there new rank as 4 in the database.
MY current script above wont work. It keeps giving wrong ranks . Can someonle look at this for me.
Regards