Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- ini_set('memory_limit', '1024M');
- error_reporting(E_ALL);
- $servername = "localhost";
- $username = "_North";
- $password = "APTR150s";
- $dbname = "4cc";
- $DB = new mysqli($servername, $username, $password, $dbname);
- if (!isset($_GET['id']))
- $_GET['id'] = 35;
- $query = "SELECT * FROM CupDB WHERE iID=" . $_GET['id'];
- echo "<h1>" . $DB->query($query)->fetch_assoc()['sName'] . "</h1>";
- $query = "SELECT * FROM PlayerDB INNER JOIN RosterOrderLookUp ON PlayerDB.sRegPos = RosterOrderLookUp.sPos WHERE iCupID = " . $_GET['id'] . " ORDER BY PlayerDB.sTeam, RosterOrderLookUp.iOrder";
- $sql = $DB->query($query);
- $arr = array();
- echo "<table id='myTable2'><tr><th></th><th onclick='sortTable(1)'>Points</th></tr>";
- while($player = $sql->fetch_assoc()){
- $sql2 = $DB->query("SELECT * FROM PerformanceDB WHERE iPlayerID=" . $player['iID']);
- $points = 0;
- $pointsStr = "";
- $playedFull = false;
- $rating = 0;
- $motmr = 20;
- $newstr = "<tr><td>" . $player['sRegPos'] . " - " . $player['sName'] . "</td>";
- $played = false;
- while($performance = $sql2->fetch_assoc()){
- $tempP = 0;
- $pointsStr .= "{";
- $sql3 = $DB->query("SELECT * FROM MatchDB WHERE iID=" . $performance['iMatchID']);
- $played = true;
- while($match = $sql3->fetch_assoc()){
- $sql4 = $DB->query("SELECT dRating FROM PerformanceDB WHERE iMatchID=" . $match['iID'] . " AND bMotM = 1");
- while ($motm = $sql4->fetch_assoc()){
- $motmr = $motm['dRating'];
- }
- $sql5 = $DB->query("SELECT * FROM EventDB INNER JOIN PlayerDB ON EventDB.iPlayerID = PlayerDB.iID WHERE iMatchID=" . $match['iID']);
- $ag = 0;
- $agd = 0;
- while($event = $sql5->fetch_assoc()){
- if ($event['iPlayerID'] == $player['iID']){
- if($event['iType'] == 1 || $event['iType'] == 4){
- if($player['iOrder'] >= 10){
- $tempP += 4; //4 points for a forward scoring a goal
- $pointsStr .= "fwd goal,";
- } else if ($player['iOrder'] >= 5){
- $tempP += 5; //5 points for a midfielder scoring a goal
- $pointsStr .= "mid goal,";
- } else {
- $tempP += 6; //6 points for a defender or goalkeeper scoring a goal
- $pointsStr .= "def goal,";
- }
- } else if ($event['iType'] == 2){
- $tempP += 3; //3 points for a goal assist
- $pointsStr .= "assist,";
- } else if ($event['iType'] == 9){
- if($player['iOrder'] > 1)
- $tempP -= 2; //-2 points for a missed penalty
- $pointsStr .= "missed pen,";
- } else if ($event['iType'] == 10){
- if($player['iOrder'] == 1 && $event['dRegTime'] >= $performance['iSubOn'] && $event['dRegTime'] <= $performance['iSubOff']){
- $tempP += 5; //5 points for a GK saving a penalty
- $pointsStr .= "saved pen,";
- } else {
- $tempP -= 2; //-2 points for a saved penalty
- $pointsStr .= "saved pen,";
- }
- } else if ($event['iType'] == 3){
- $tempP -= 2; //-2 points for an own goal
- $pointsStr .= "own goal,";
- } else if ($event['iType'] == 5){
- $tempP -= 1; //-1 point for a yellow card
- $pointsStr .= "yellow,";
- } else if ($event['iType'] == 6){
- $tempP -= 3; //-3 points for a straight red
- $pointsStr .= "red,";
- } else if ($event['iType'] == 8){
- $tempP -= 4; //-4 points for a red resulting from 2 yellows
- $pointsStr .= "2nd yellow,";
- }
- }
- if ((($event['iType'] == 1 || $event['iType'] == 4) && $event['sTeam'] != $player['sTeam']) || ($event['iType'] == 3 && $event['sTeam'] == $player['sTeam'])){
- $ag++;
- if ($event['dRegTime'] >= $performance['iSubOn'] && $event['dRegTime'] <= $performance['iSubOff']){
- $agd++;
- }
- }
- }
- }
- if ($ag == 0){
- if ($player['iOrder'] < 5){
- if ($performance['iSubOff'] - $performance['iSubOn'] >= 60){
- $tempP += 4; //4 points for a defender or goalkeeper p
- $pointsStr .= "60+ def clean sheet,";
- } else {
- $tempP += 3;
- $pointsStr .= "60- def clean sheet,";
- }
- } else if ($player['iOrder'] < 10 && $performance['iSubOff'] - $performance['iSubOn'] >= 60){
- $tempP +=1;
- $pointsStr .= "mid clean sheet,";
- }
- }
- if ($agd >= 2 && $player['iOrder'] < 5){
- $tempP -= floor($agd / 2);
- $pointsStr .= "goals in -" . floor($agd / 2) . "pts,";
- }
- if ($performance['dRating'] > 0){
- $tempP += floor($performance['dRating'] - 4);
- $pointsStr .= floor($performance['dRating'] - 4) . " rating p, ";
- }
- if ($performance['iSaves']>0){
- $tempP += floor($performance['iSaves'] / 2);
- $pointsStr .= floor($performance['iSaves'] / 2) . " save p,";
- }
- $rating = $performance['dRating'];
- if ($performance['bMotM']){
- $tempP += 3;
- $pointsStr .= "motm,";
- } else if($rating >= $motmr){
- $tempP += 2;
- $pointsStr .= "equal motm,";
- } else if($rating + 0.5 >= $motmr){
- $tempP += 1;
- $pointsStr .= "almost equal motm,";
- }
- $DB->query("UPDATE PerformanceDB SET iFF=$tempP WHERE iID=" . $performance['iID']);
- $points += $tempP;
- $pointsStr .= "=$tempP} ";
- $newstr .= "<td>" . $tempP . "</td>";
- }
- if ($played == false){
- //echo "<td>-</td>";
- }
- //$arr[$player['sName'] . " (" . trim($pointsStr) . ")"] = $points;
- //echo "</tr>";
- $arr[$newstr . "</tr>"] = $points;
- }
- if (isset($_GET['order']))
- arsort($arr);
- foreach($arr as $key=>$val){
- //echo "$val - $key <hr>";
- echo $key;
- }
- echo "</table>";
- ?>
- <STYLE>
- table {
- border-collapse: collapse;
- }
- table, th, td {
- border: 1px solid black;
- }
- </STYLE>
- <script>
- function sortTablea(n) {
- var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
- table = document.getElementById("myTable2");
- switching = true;
- // Set the sorting direction to ascending:
- dir = "asc";
- /* Make a loop that will continue until
- no switching has been done: */
- while (switching) {
- // Start by saying: no switching is done:
- switching = false;
- rows = table.rows;
- /* Loop through all table rows (except the
- first, which contains table headers): */
- for (i = 1; i < (rows.length - 1); i++) {
- // Start by saying there should be no switching:
- shouldSwitch = false;
- /* Get the two elements you want to compare,
- one from current row and one from the next: */
- x = rows[i].getElementsByTagName("TD")[n];
- y = rows[i + 1].getElementsByTagName("TD")[n];
- /* Check if the two rows should switch place,
- based on the direction, asc or desc: */
- if (dir == "asc") {
- if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
- // If so, mark as a switch and break the loop:
- shouldSwitch = true;
- break;
- }
- } else if (dir == "desc") {
- if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
- // If so, mark as a switch and break the loop:
- shouldSwitch = true;
- break;
- }
- }
- }
- if (shouldSwitch) {
- /* If a switch has been marked, make the switch
- and mark that a switch has been done: */
- rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
- switching = true;
- // Each time a switch is done, increase this count by 1:
- switchcount ++;
- } else {
- /* If no switching has been done AND the direction is "asc",
- set the direction to "desc" and run the while loop again. */
- if (switchcount == 0 && dir == "asc") {
- dir = "desc";
- switching = true;
- }
- }
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement