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.

playertable.php 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?PHP
  2. function showPlayerTable($joins = '', $where = '1=1', $limit = 20, $hideclass = false, $userank = false, $highlight = 0) {
  3. $more = false;
  4. echo '<table>', "\n";
  5. echo '<tr>', "\n";
  6. echo '<th rowspan="2">Rank</th><th rowspan="2">Alias</th><th rowspan="2">Kills</th><th rowspan="2">Deaths</th><th rowspan="2"><abbr title="Kills per Death">KPD</abbr></th><th rowspan="2">Score</th>';
  7. echo '<th colspan="', $hideclass ? '1' : '2', '">Mostly seen &hellip;</th></tr>', "\n";
  8. echo '<tr>', $hideclass ? '' : '<th>Playing as</th>', '<th>Killing with</th></tr>', "\n";
  9. $sql = "SELECT players.player_id, player_rank, player_score, session_alias, SUM(roleperiod_kills) AS kills, SUM(roleperiod_deaths) AS deaths, SUM(roleperiod_kills)/SUM(roleperiod_deaths) AS kpd FROM players NATURAL JOIN sessions INNER JOIN roleperiods ON roleperiods.session_id = sessions.session_id $joins WHERE player_rank > 0 AND $where GROUP BY player_id ORDER BY " . (($where == '1=1' || $userank) ? 'player_rank' : 'kpd DESC') . " LIMIT $limit";
  10. $res = mysql_query($sql) or print(mysql_error());
  11. $i = 0;
  12. if (mysql_num_rows($res) == 0) {
  13. echo '<tr><td colspan="8" class="none">No results found</td></tr>';
  14. }
  15. while ($row = mysql_fetch_assoc($res)) {
  16. if (!$hideclass) {
  17. $sql = "SELECT class_name, class_displayname FROM roleperiods NATURAL JOIN classes NATURAL JOIN sessions WHERE roleperiod_endtime > '0000-00-00' AND player_id = " . $row['player_id'] . " GROUP BY class_id ORDER BY SUM(roleperiod_endtime - roleperiod_starttime) DESC LIMIT 0,1";
  18. $re2 = mysql_query($sql) or print(mysql_error());
  19. }
  20. $sql = "SELECT weapon_name, COUNT(*) AS times FROM roleperiods INNER JOIN kills ON kills.kill_killer = roleperiod_id NATURAL JOIN weapons NATURAL JOIN sessions WHERE player_id = " .$row['player_id'] . " GROUP BY weapon_displayname ORDER BY times DESC LIMIT 0,1";
  21. $re3 = mysql_query($sql) or print($sql . '<br>' . mysql_error());
  22. $i++;
  23. $hclass = $row['player_id'] == $highlight ? 'highlight' : '';
  24. if ($i % 2 == 0) {
  25. $class = ' class="even ' . $hclass . '"';
  26. } else if ($hclass != '') {
  27. $class = ' class="' . $hclass . '"';
  28. } else {
  29. $class = '';
  30. }
  31. echo '<tr', $class, '><td>', ($where == '1=1' || $userank) ? $row['player_rank'] : $i, '</td>';
  32. echo '<td>';
  33. if ($highlight != $row['player_id']) {
  34. echo '<a href="player.php?id=', $row['player_id'], '">';
  35. }
  36. echo htmlentities($row['session_alias'], ENT_COMPAT, 'UTF-8');
  37. if ($highlight != $row['player_id']) {
  38. echo '</a>';
  39. }
  40. echo '</td><td class="num">', number_format($row['kills']), '</td><td class="num">', number_format($row['deaths']), '</td>';
  41. echo '<td class="num">', number_format($row['kpd'], 2), '</td>';
  42. echo '<td class="num">', number_format($row['player_score'], 0), '</td>';
  43. if (!$hideclass) {
  44. echo '<td class="class">';
  45. echo '<a href="', URL_BASE, 'class.php?class=', mysql_result($re2, 0), '">';
  46. echo '<img src="', sprintf(URL_CLASS, 'blue', mysql_result($re2, 0)), '"></a></td>';
  47. }
  48. echo '<td class="weapon">';
  49. if (mysql_num_rows($re3) > 0) {
  50. echo '<img src="/stats/res/weapons/', mysql_result($re3, 0), '.png">';
  51. } else {
  52. echo 'Nothing';
  53. }
  54. echo '</td>';
  55. echo '</tr>', "\n";
  56. }
  57. echo '</table>', "\n";
  58. }