Guest User

Untitled

a guest
Aug 19th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Test-data baseret på: id - playerid - teamid - kills - assist - bombspla - bombsdef - flag - ...mm... - game - season
  6.  *
  7.  * Linie 9 til 27 er blot en emulering af data hentet fra databasen
  8.  */
  9. $entry = array();
  10.  
  11. for($i = 10; $i > 0; $i--)
  12. {
  13.     for($x = 0; $x < 100; $x++)
  14.     {
  15.         $tmp = new stdClass();
  16.         $tmp->season = $i;
  17.         $tmp->playerid = rand(1, 15);
  18.         $tmp->kills = rand(1, 15);
  19.         $tmp->assist = rand(1, 15);
  20.         $tmp->bombspla = rand(1, 15);
  21.         $tmp->bombsdef = rand(1, 15);
  22.         $tmp->flag = rand(1, 15);
  23.         $tmp->game = rand(1, 5);
  24.         $entry[] = $tmp;
  25.     }
  26.    
  27. }
  28.  
  29. $players = array(); // Gemmer data på spilelrne
  30. $seasons = array(); // Til at tælle antal aktive sæsoner
  31. foreach($entry as $value) // Gennemløb alle data
  32. {
  33.     if(!in_array($value->season, $seasons))
  34.     {
  35.         $seasons[] = $value->season;
  36.     }
  37.    
  38.     if(!isset($players[$value->playerid]))
  39.     {
  40.         $players[$value->playerid] = array();
  41.     }
  42.    
  43.     if(!isset($seasons[$value->playerid][$value->season]))
  44.     {
  45.         $players[$value->playerid][$value->season] = array();
  46.         $players[$value->playerid][$value->season]['points'] = 0;
  47.     }
  48.        
  49.     // Læg alle data sammen for denne linie
  50.     $entry_points = $value->kills + $value->assist + $value->bombspla + $value->bombsdef + $value->flag;
  51.     //Læg til de point som allerede er registreret i den sæson.
  52.     $players[$value->playerid][$value->season]['points'] += $entry_points;
  53. }
  54.  
  55. // Sorter spillernes rang efter den første sæson
  56. $num_seasons = count($seasons);
  57. uasort($players, function($a, $b) use ($num_seasons) {
  58.        
  59.     if ($a[$num_seasons]['points'] == $b[$num_seasons]['points']) {
  60.         return 0;
  61.     }
  62.     return ($a[$num_seasons]['points'] > $b[$num_seasons]['points']) ? -1 : 1;
  63.    
  64. });
  65.  
  66. ?>
  67. <!DOCTYPE html>
  68. <html lang="en">
  69.     <head>
  70.         <title>Team test</title>
  71.     </head>
  72.     <body>
  73.    
  74.         <table>
  75.             <thead>
  76.                 <tr>
  77.                     <th>Spiller</th>   
  78.                     <?php for($i = $num_seasons; $i > 0; $i--): ?>
  79.                     <th>Sæson <?php echo $i; ?></th>
  80.                     <?php endfor; ?>
  81.                 </tr>  
  82.             </thead>
  83.             <tbody>
  84.                 <?php foreach($players as $player_id => $seasons): ?>
  85.                 <tr>
  86.                     <td>Spiller <?php echo $player_id; ?></td>
  87.                     <?php foreach($seasons as $season): ?>
  88.                     <td><?php echo $season['points']; ?></td>
  89.                     <?php endforeach; ?>
  90.                 </tr>
  91.                 <?php endforeach; ?>
  92.             </tbody>
  93.         </table>
  94.    
  95.     </body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment