Unsupported PHP app for analysing and displaying stats for Team Fortress 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updateranks.php 1002B

12345678910111213141516171819202122232425262728293031323334
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/database.php');
  3. function updateRanks() {
  4. $sql = 'SELECT player_id, player_rank, player_score, SUM(roleperiod_kills) AS kills FROM players NATURAL JOIN roleperiods GROUP BY player_id ORDER BY player_score DESC';
  5. $res = mysql_query($sql);
  6. echo "Updating player ranks... ";
  7. $i = $updated = $limited = 0;
  8. $left = array();
  9. while ($row = mysql_fetch_assoc($res)) {
  10. if ($row['kills'] < MIN_KILLS) {
  11. $left[$row['player_id']] = $row['player_score'];
  12. } else {
  13. if ($row['player_rank'] != ++$i) {
  14. mysql_query('UPDATE players SET player_rank = ' . $i . ' WHERE player_id = ' . $row['player_id']);
  15. $updated++;
  16. }
  17. }
  18. }
  19. arsort($left);
  20. foreach ($left as $player => $score) {
  21. mysql_query('UPDATE players SET player_rank = ' . (++$i) . ' WHERE player_id = ' . $player);
  22. $updated++; $limited++;
  23. }
  24. echo "Done.\n\t$updated player records updated.\n\t$limited players rank-limited by their number of kills.\n";
  25. }
  26. ?>