Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * Test-data baseret på: id - playerid - teamid - kills - assist - bombspla - bombsdef - flag - ...mm... - game - season
- *
- * Linie 9 til 27 er blot en emulering af data hentet fra databasen
- */
- $entry = array();
- for($i = 10; $i > 0; $i--)
- {
- for($x = 0; $x < 100; $x++)
- {
- $tmp = new stdClass();
- $tmp->season = $i;
- $tmp->playerid = rand(1, 15);
- $tmp->kills = rand(1, 15);
- $tmp->assist = rand(1, 15);
- $tmp->bombspla = rand(1, 15);
- $tmp->bombsdef = rand(1, 15);
- $tmp->flag = rand(1, 15);
- $tmp->game = rand(1, 5);
- $entry[] = $tmp;
- }
- }
- $players = array(); // Gemmer data på spilelrne
- $seasons = array(); // Til at tælle antal aktive sæsoner
- foreach($entry as $value) // Gennemløb alle data
- {
- if(!in_array($value->season, $seasons))
- {
- $seasons[] = $value->season;
- }
- if(!isset($players[$value->playerid]))
- {
- $players[$value->playerid] = array();
- }
- if(!isset($seasons[$value->playerid][$value->season]))
- {
- $players[$value->playerid][$value->season] = array();
- $players[$value->playerid][$value->season]['points'] = 0;
- }
- // Læg alle data sammen for denne linie
- $entry_points = $value->kills + $value->assist + $value->bombspla + $value->bombsdef + $value->flag;
- //Læg til de point som allerede er registreret i den sæson.
- $players[$value->playerid][$value->season]['points'] += $entry_points;
- }
- // Sorter spillernes rang efter den første sæson
- $num_seasons = count($seasons);
- uasort($players, function($a, $b) use ($num_seasons) {
- if ($a[$num_seasons]['points'] == $b[$num_seasons]['points']) {
- return 0;
- }
- return ($a[$num_seasons]['points'] > $b[$num_seasons]['points']) ? -1 : 1;
- });
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Team test</title>
- </head>
- <body>
- <table>
- <thead>
- <tr>
- <th>Spiller</th>
- <?php for($i = $num_seasons; $i > 0; $i--): ?>
- <th>Sæson <?php echo $i; ?></th>
- <?php endfor; ?>
- </tr>
- </thead>
- <tbody>
- <?php foreach($players as $player_id => $seasons): ?>
- <tr>
- <td>Spiller <?php echo $player_id; ?></td>
- <?php foreach($seasons as $season): ?>
- <td><?php echo $season['points']; ?></td>
- <?php endforeach; ?>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment