Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. ini_set('memory_limit', '1024M');
  5. error_reporting(E_ALL);
  6.  
  7. $servername = "localhost";
  8. $username = "_North";
  9. $password = "APTR150s";
  10. $dbname = "4cc";
  11. $DB = new mysqli($servername, $username, $password, $dbname);
  12. if (!isset($_GET['id']))
  13. $_GET['id'] = 35;
  14. $query = "SELECT * FROM CupDB WHERE iID=" . $_GET['id'];
  15. echo "<h1>" . $DB->query($query)->fetch_assoc()['sName'] . "</h1>";
  16. $query = "SELECT * FROM PlayerDB INNER JOIN RosterOrderLookUp ON PlayerDB.sRegPos = RosterOrderLookUp.sPos WHERE iCupID = " . $_GET['id'] . " ORDER BY PlayerDB.sTeam, RosterOrderLookUp.iOrder";
  17. $sql = $DB->query($query);
  18. $arr = array();
  19. echo "<table id='myTable2'><tr><th></th><th onclick='sortTable(1)'>Points</th></tr>";
  20. while($player = $sql->fetch_assoc()){
  21. $sql2 = $DB->query("SELECT * FROM PerformanceDB WHERE iPlayerID=" . $player['iID']);
  22. $points = 0;
  23. $pointsStr = "";
  24. $playedFull = false;
  25. $rating = 0;
  26. $motmr = 20;
  27. $newstr = "<tr><td>" . $player['sRegPos'] . " - " . $player['sName'] . "</td>";
  28. $played = false;
  29. while($performance = $sql2->fetch_assoc()){
  30. $tempP = 0;
  31. $pointsStr .= "{";
  32. $sql3 = $DB->query("SELECT * FROM MatchDB WHERE iID=" . $performance['iMatchID']);
  33. $played = true;
  34. while($match = $sql3->fetch_assoc()){
  35. $sql4 = $DB->query("SELECT dRating FROM PerformanceDB WHERE iMatchID=" . $match['iID'] . " AND bMotM = 1");
  36. while ($motm = $sql4->fetch_assoc()){
  37. $motmr = $motm['dRating'];
  38. }
  39. $sql5 = $DB->query("SELECT * FROM EventDB INNER JOIN PlayerDB ON EventDB.iPlayerID = PlayerDB.iID WHERE iMatchID=" . $match['iID']);
  40. $ag = 0;
  41. $agd = 0;
  42. while($event = $sql5->fetch_assoc()){
  43. if ($event['iPlayerID'] == $player['iID']){
  44. if($event['iType'] == 1 || $event['iType'] == 4){
  45. if($player['iOrder'] >= 10){
  46. $tempP += 4; //4 points for a forward scoring a goal
  47. $pointsStr .= "fwd goal,";
  48. } else if ($player['iOrder'] >= 5){
  49. $tempP += 5; //5 points for a midfielder scoring a goal
  50. $pointsStr .= "mid goal,";
  51. } else {
  52. $tempP += 6; //6 points for a defender or goalkeeper scoring a goal
  53. $pointsStr .= "def goal,";
  54. }
  55. } else if ($event['iType'] == 2){
  56. $tempP += 3; //3 points for a goal assist
  57. $pointsStr .= "assist,";
  58. } else if ($event['iType'] == 9){
  59. if($player['iOrder'] > 1)
  60. $tempP -= 2; //-2 points for a missed penalty
  61. $pointsStr .= "missed pen,";
  62. } else if ($event['iType'] == 10){
  63. if($player['iOrder'] == 1 && $event['dRegTime'] >= $performance['iSubOn'] && $event['dRegTime'] <= $performance['iSubOff']){
  64. $tempP += 5; //5 points for a GK saving a penalty
  65. $pointsStr .= "saved pen,";
  66. } else {
  67. $tempP -= 2; //-2 points for a saved penalty
  68. $pointsStr .= "saved pen,";
  69. }
  70. } else if ($event['iType'] == 3){
  71. $tempP -= 2; //-2 points for an own goal
  72. $pointsStr .= "own goal,";
  73. } else if ($event['iType'] == 5){
  74. $tempP -= 1; //-1 point for a yellow card
  75. $pointsStr .= "yellow,";
  76. } else if ($event['iType'] == 6){
  77. $tempP -= 3; //-3 points for a straight red
  78. $pointsStr .= "red,";
  79. } else if ($event['iType'] == 8){
  80. $tempP -= 4; //-4 points for a red resulting from 2 yellows
  81. $pointsStr .= "2nd yellow,";
  82. }
  83. }
  84. if ((($event['iType'] == 1 || $event['iType'] == 4) && $event['sTeam'] != $player['sTeam']) || ($event['iType'] == 3 && $event['sTeam'] == $player['sTeam'])){
  85. $ag++;
  86. if ($event['dRegTime'] >= $performance['iSubOn'] && $event['dRegTime'] <= $performance['iSubOff']){
  87. $agd++;
  88. }
  89. }
  90. }
  91. }
  92. if ($ag == 0){
  93. if ($player['iOrder'] < 5){
  94. if ($performance['iSubOff'] - $performance['iSubOn'] >= 60){
  95. $tempP += 4; //4 points for a defender or goalkeeper p
  96. $pointsStr .= "60+ def clean sheet,";
  97. } else {
  98. $tempP += 3;
  99. $pointsStr .= "60- def clean sheet,";
  100. }
  101. } else if ($player['iOrder'] < 10 && $performance['iSubOff'] - $performance['iSubOn'] >= 60){
  102. $tempP +=1;
  103. $pointsStr .= "mid clean sheet,";
  104. }
  105. }
  106. if ($agd >= 2 && $player['iOrder'] < 5){
  107. $tempP -= floor($agd / 2);
  108. $pointsStr .= "goals in -" . floor($agd / 2) . "pts,";
  109. }
  110. if ($performance['dRating'] > 0){
  111. $tempP += floor($performance['dRating'] - 4);
  112. $pointsStr .= floor($performance['dRating'] - 4) . " rating p, ";
  113. }
  114. if ($performance['iSaves']>0){
  115. $tempP += floor($performance['iSaves'] / 2);
  116. $pointsStr .= floor($performance['iSaves'] / 2) . " save p,";
  117. }
  118. $rating = $performance['dRating'];
  119. if ($performance['bMotM']){
  120. $tempP += 3;
  121. $pointsStr .= "motm,";
  122. } else if($rating >= $motmr){
  123. $tempP += 2;
  124. $pointsStr .= "equal motm,";
  125. } else if($rating + 0.5 >= $motmr){
  126. $tempP += 1;
  127. $pointsStr .= "almost equal motm,";
  128. }
  129. $DB->query("UPDATE PerformanceDB SET iFF=$tempP WHERE iID=" . $performance['iID']);
  130. $points += $tempP;
  131. $pointsStr .= "=$tempP} ";
  132. $newstr .= "<td>" . $tempP . "</td>";
  133. }
  134. if ($played == false){
  135. //echo "<td>-</td>";
  136. }
  137. //$arr[$player['sName'] . " (" . trim($pointsStr) . ")"] = $points;
  138. //echo "</tr>";
  139. $arr[$newstr . "</tr>"] = $points;
  140.  
  141. }
  142. if (isset($_GET['order']))
  143. arsort($arr);
  144. foreach($arr as $key=>$val){
  145. //echo "$val - $key <hr>";
  146. echo $key;
  147. }
  148. echo "</table>";
  149. ?>
  150. <STYLE>
  151. table {
  152. border-collapse: collapse;
  153. }
  154.  
  155. table, th, td {
  156. border: 1px solid black;
  157. }
  158. </STYLE>
  159. <script>
  160. function sortTablea(n) {
  161. var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  162. table = document.getElementById("myTable2");
  163. switching = true;
  164. // Set the sorting direction to ascending:
  165. dir = "asc";
  166. /* Make a loop that will continue until
  167. no switching has been done: */
  168. while (switching) {
  169. // Start by saying: no switching is done:
  170. switching = false;
  171. rows = table.rows;
  172. /* Loop through all table rows (except the
  173. first, which contains table headers): */
  174. for (i = 1; i < (rows.length - 1); i++) {
  175. // Start by saying there should be no switching:
  176. shouldSwitch = false;
  177. /* Get the two elements you want to compare,
  178. one from current row and one from the next: */
  179. x = rows[i].getElementsByTagName("TD")[n];
  180. y = rows[i + 1].getElementsByTagName("TD")[n];
  181. /* Check if the two rows should switch place,
  182. based on the direction, asc or desc: */
  183. if (dir == "asc") {
  184. if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
  185. // If so, mark as a switch and break the loop:
  186. shouldSwitch = true;
  187. break;
  188. }
  189. } else if (dir == "desc") {
  190. if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
  191. // If so, mark as a switch and break the loop:
  192. shouldSwitch = true;
  193. break;
  194. }
  195. }
  196. }
  197. if (shouldSwitch) {
  198. /* If a switch has been marked, make the switch
  199. and mark that a switch has been done: */
  200. rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  201. switching = true;
  202. // Each time a switch is done, increase this count by 1:
  203. switchcount ++;
  204. } else {
  205. /* If no switching has been done AND the direction is "asc",
  206. set the direction to "desc" and run the while loop again. */
  207. if (switchcount == 0 && dir == "asc") {
  208. dir = "desc";
  209. switching = true;
  210. }
  211. }
  212. }
  213. }
  214. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement