/content/svs3_stats_gameday2.php

https://github.com/miguelwicht/SVS-Web-App · PHP · 251 lines · 141 code · 90 blank · 20 comment · 11 complexity · 89b30b5967d401cb0e2694ba830d2d4d MD5 · raw file

  1. <?
  2. $cachefile ="svs3_stats_gameday.html";
  3. ob_start();
  4. ?>
  5. <?
  6. include("../mysql/dbConnect.php");
  7. mysql_query("set names utf8;");
  8. /*
  9. $query="SELECT * FROM svs3_1112_player ORDER BY lastName ASC";
  10. $result=mysql_query($query);
  11. $num=mysql_numrows($result);
  12. */
  13. /*
  14. $query = "SELECT p.firstName AS firstName, p.lastName AS lastName, COUNT(DISTINCT g.goal_id) AS goals, COUNT(DISTINCT a.assist_id) AS assists, COUNT(DISTINCT y.yellow_id) AS yellow, COUNT(DISTINCT r.red_id) AS red FROM svs3_1112_gamedayParticipants AS pa LEFT JOIN svs3_1112_player AS p ON pa.player_id = p.id LEFT JOIN svs3_1112_goals AS g ON p.id = g.player_id LEFT JOIN svs3_1112_assists AS a ON p.id = a.player_id LEFT JOIN svs3_1112_yellow AS y ON p.id = y.player_id LEFT JOIN svs3_1112_red AS r ON p.id = r.player_id GROUP BY pa.gameday_id ORDER BY lastName ASC";
  15. */
  16. /*
  17. $query = "SELECT p.firstName AS firstName, p.lastName AS lastName FROM svs3_1112_gamedayParticipants AS pa LEFT JOIN svs3_1112_player AS p ON pa.player_id = p.id UNION (SELECT COUNT(*) AS goals FROM svs3_1112_goals AS g WHERE g.gameday_id = pa.gameday_id AND pa.player_id = p.id) UNION (SELECT COUNT(*) AS assists FROM svs3_1112_assists AS a WHERE a.gameday_id = pa.gameday_id AND pa.player_id = p.id) UNION (SELECT COUNT(*) AS yellows FROM svs3_1112_yellow AS y WHERE y.gameday_id = pa.gameday_id AND pa.player_id = p.id) UNION (SELECT COUNT(*) AS reds FROM svs3_1112_red AS r WHERE r.gameday_id = pa.gameday_id AND pa.player_id = p.id) GROUP BY p.id ORDER BY lastName ASC";
  18. */
  19. $query = "SELECT p.firstName AS firstName, p.lastName AS lastName FROM svs3_1112_gamedayParticipants AS pa LEFT JOIN svs3_1112_player AS p ON pa.player_id = p.id UNION (SELECT COUNT(*) AS goals FROM svs3_1112_goals AS g) UNION (SELECT COUNT(*) AS assists FROM svs3_1112_assists AS a) UNION (SELECT COUNT(*) AS yellows FROM svs3_1112_yellow AS y) UNION (SELECT COUNT(*) AS reds FROM svs3_1112_red AS r) GROUP BY p.id ORDER BY lastName ASC";
  20. $result=mysql_query($query);
  21. $statistic = array();
  22. while ($row = mysql_fetch_assoc($result)) {
  23. $statistic[]= $row;
  24. }
  25. echo mysql_error();
  26. print_r($result);
  27. $queries = array();
  28. $results = array();
  29. $queries['gamedays'] = "SELECT * FROM svs3_1112_gamedays ASC";
  30. $queries['gameday_team'] = "SELECT * FROM svs3_1112_gamedayParticipants AS pa LEFT JOIN svs3_1112_player AS p ON pa.participant_id = p.id LEFT JOIN";
  31. $results['gamedays'] = mysql_query($queries['gamedays']);
  32. ?>
  33. <?
  34. //get number of gamedays
  35. $gamedays_count_query="SELECT COUNT(*) FROM svs3_1112_gamedays";
  36. $gamedays_count_result=mysql_query($gamedays_count_query);
  37. $gamedays_count=mysql_result($gamedays_count_result,0);
  38. ?>
  39. <ul>
  40. <?
  41. $opponent_query="SELECT * FROM svs3_1112_opponents ORDER BY id ASC";
  42. $opponent_result=mysql_query($opponent_query);
  43. $opponent_num=mysql_numrows($opponent_result);
  44. $opponents = array(); /* initialize empty array */
  45. while($opponent = mysql_fetch_assoc($opponent_result)) { /* iterating only once over the result set! */
  46. $opponents[] = $opponent;
  47. }
  48. ?>
  49. <?
  50. for ($z=1; $z<=$gamedays_count; $z++){
  51. $gameday_opponent_query="SELECT * FROM svs3_1112_gamedays WHERE gameday ='$z'";
  52. $gameday_opponent_result=mysql_query($gameday_opponent_query);
  53. $gegner=mysql_result($gameday_opponent_result,0,'opponent');
  54. $gameday_opponent[$z]['opponent']= $opponents[$gegner-1]['club'];
  55. $gameday_opponent[$z]['date']=mysql_result($gameday_opponent_result,0,'date');
  56. $gameday_opponent[$z]['home']=mysql_result($gameday_opponent_result,0,'home');
  57. $gameday_opponent[$z]['opponentGoals']=mysql_result($gameday_opponent_result,0,'opponentGoals');
  58. $ownGoals_query="SELECT COUNT(*) FROM svs3_1112_ownGoals WHERE gameday ='$z'";
  59. $ownGoals_result=mysql_query($ownGoals_query);
  60. $ownGoals_count=mysql_result($ownGoals_result,0);
  61. $goals_result_query="SELECT COUNT(*) FROM svs3_1112_goals WHERE gameday_id = '$z'";
  62. $goals_result_result=mysql_query($goals_result_query);
  63. $goals_result_count=mysql_result($goals_result_result,0);
  64. ?>
  65. <li>
  66. <?
  67. if ($gameday_opponent[$z]['home']){
  68. echo '<h3 class="gameday_headline">Spieltag '.$z.' - ['.($goals_result_count+$ownGoals_count).' : '.$gameday_opponent[$z]['opponentGoals'].'] SVS III gg. '.$gameday_opponent[$z]['opponent'].'</h3>';
  69. } else {
  70. echo '<h3 class="gameday_headline">Spieltag '.$z.' - ['.$gameday_opponent[$z]['opponentGoals'].' : '.($goals_result_count+$ownGoals_count).'] '.$gameday_opponent[$z]['opponent'].' gg. SVS III</h3>';
  71. }
  72. ?>
  73. </li>
  74. <li class="gameday_li">
  75. <table>
  76. <tr>
  77. <th>Nr.</th>
  78. <th>Name</th>
  79. <th>T</th>
  80. <th>V</th>
  81. <th>G</th>
  82. <th>R</th>
  83. </tr>
  84. <?
  85. $i=0;
  86. $count=1;
  87. //get number of participants
  88. $participants_count_query="SELECT COUNT(*) FROM svs3_1112_gamedayParticipants WHERE gameday_id = '$z'";
  89. $participants_count_result=mysql_query($participants_count_query);
  90. $participants_count=mysql_result($participants_count_result,0);
  91. while ($i <= $participants_count-1) { //limit loop to number of participants
  92. //$id=mysql_result($result,$i,"id");
  93. //get participants for specific game
  94. $participants_query="SELECT * FROM svs3_1112_gamedayParticipants WHERE gameday_id = '$z'";
  95. $participants_result=mysql_query($participants_query);
  96. $participants[] = mysql_result($participants_result,$i,"player_id");
  97. $participants_names_query = "SELECT * FROM svs3_1112_player WHERE id = '$participants[$i]'";
  98. $participants_names_result = mysql_query($participants_names_query);
  99. $firstName = mysql_result($participants_names_result,0,"firstName");
  100. $lastName = mysql_result($participants_names_result,0,"lastName");
  101. $participants_names[$participants[$i]] = $lastName.', '.$firstName;
  102. $goals_query="SELECT COUNT(*) FROM svs3_1112_goals WHERE player_id = '$participants[$i]' && gameday_id = '$z'";
  103. $goals_result=mysql_query($goals_query);
  104. $goals_count=mysql_result($goals_result,0);
  105. $participants_goals[$participants[$i]] = $goals_count;
  106. $assists_query="SELECT COUNT(*) FROM svs3_1112_assists WHERE player_id = '$participants[$i]' && gameday_id = '$z'";
  107. $assists_result=mysql_query($assists_query);
  108. $assists_count=mysql_result($assists_result,0);
  109. $participants_assists[$participants[$i]] = $assists_count;
  110. $yellow_query="SELECT COUNT(*) FROM svs3_1112_yellow WHERE player_id = '$participants[$i]' && gameday_id = '$z'";
  111. $yellow_result=mysql_query($yellow_query);
  112. $yellow_count=mysql_result($yellow_result,0);
  113. $participants_yellow[$participants[$i]] = $yellow_count;
  114. $red_query="SELECT COUNT(*) FROM svs3_1112_red WHERE player_id = '$participants[$i]' && gameday_id = '$z'";
  115. $red_result=mysql_query($red_query);
  116. $red_count=mysql_result($red_result,0);
  117. $participants_red[$participants[$i]] = $red_count;
  118. //$trikots_query="SELECT COUNT(*) FROM svs3_1112_trikots WHERE player_id = '$participants[$i]' && gameday_id = '1'";
  119. //$trikots_result=mysql_query($trikots_query);
  120. //$trikots_count=mysql_result($trikots_result,0);
  121. ?>
  122. <? if ($participants_count > 0) { ?>
  123. <? if ($count&1) $class = "odd";?>
  124. <tr class="<? echo $class;?>">
  125. <td><? echo $count ?></td>
  126. <td><? echo $participants_names[$participants[$i]];?></td>
  127. <td><? echo $participants_goals[$participants[$i]];?></td>
  128. <td><? echo $participants_assists[$participants[$i]];?></td>
  129. <td><? echo $participants_yellow[$participants[$i]];?></td>
  130. <td><? echo $participants_red[$participants[$i]];?></td>
  131. </tr>
  132. <? $class = "even" ?>
  133. <?
  134. $count++;
  135. }
  136. ?>
  137. <?
  138. $i++;
  139. }
  140. ?>
  141. </table>
  142. <?
  143. unset($participants);
  144. unset($particioants_names);
  145. unset($particioants_goals);
  146. unset($particioants_assists);
  147. unset($particioants_yellow);
  148. unset($particioants_red);
  149. echo '</li>';
  150. } //for $z end
  151. mysql_close();
  152. ?>
  153. </ul>
  154. <?
  155. $fp =fopen($cachefile,'w');
  156. fwrite($fp, ob_get_contents());
  157. fclose($fp);
  158. ob_end_flush();
  159. ?>