-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixtures.php
122 lines (104 loc) · 3.2 KB
/
fixtures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
session_start();
include 'includes/checklog.inc.php';
include 'includes/connect.inc.php';
function countEvent ($conn, $match, $event, $team) {
$query = 'SELECT COUNT(*) AS num FROM match_events AS me
LEFT JOIN player_team AS pt ON pt.player_id = me.player_id
LEFT JOIN players AS p ON p.player_id = me.player_id
LEFT JOIN events AS e ON e.event_id = me.event_id
WHERE me.match_id = '. $match .' AND e.event_name ="'. $event .'" AND pt.team_id = '. $team .';';
$result = $conn->query($query);
$row = $result->fetch_assoc();
$num = $row['num'];
return $num;
}
$league_id = $_SESSION['league_id'];
$query = "SELECT * FROM leagues WHERE league_id = " . $league_id . ";";
$result = $conn->query($query);
$row = $result->fetch_assoc();
$num_weeks = $row['league_weeks'];
$sql = "SELECT COUNT(*) AS num_teams FROM teams WHERE league_id ='".$league_id."';";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$num_teams = $row['num_teams'];
$_SESSION['teamnum']= $num_teams;
if ($num_teams%2==1){
$matchesPerRound=($num_teams - 1)/2;
}else{
$matchesPerRound=($num_teams)/2;
}
if(!isset($_POST['week'])){
$week=1;
} else {
$week = (int)$_POST['week'];
}
$query = "SELECT matches.status, matches.team1_id, matches.team2_id, FT.team_name AS first, matches.match_id, matches.week_no, matches.round_no, ST.team_name AS second
FROM matches
LEFT JOIN teams AS FT ON matches.team1_id = FT.team_id
LEFT JOIN teams AS ST ON matches.team2_id = ST.team_id
WHERE FT.league_id = ". $league_id ." AND matches.team1_id = FT.team_id
AND matches.week_no = ". $week ."
ORDER BY matches.match_id;" ;
//
$result = $conn->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Fixtures</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="leaguedashboard.php" method="post">
<input type="submit" name="submit" value="Go back">
</form><br/>
<form method="post" >
<select name='week'>
<?php
for($i = 0; $i < $num_weeks; $i++){
echo '<option value=' . ($i + 1) . '>Week '. ($i + 1) . '</option>';
}
?>
</select>
<input type='submit' name='submit'value='select'>
</form>
<?php
echo '<h1>WEEK '. $week . '</h1><br/>';
?>
<form method="post" action="scripts/openmatch.s.php">
<?php
$i=0;
$j=1;
while($row=$result->fetch_assoc()){
if ($i==$matchesPerRound){
$i=0;
}
if($i==0){
echo '<h4>Round ' . $j . '</h4>';
$j++;
}
//$query = "SELECT COUNT(*) FROM match_events WHERE ma"
$team1 = $row['team1_id'];
$team2 = $row['team2_id'];
$match_id = $row['match_id'];
$first = $row['first'];
$second = $row['second'];
$status = $row['status'];
echo '<label class="fixture">'. $first . ' vs ' . $second . '</label>';
$team1_goals_scored = countEvent($conn, $match_id, 'goal', $team1);
$team2_own_goals = countEvent($conn, $match_id, 'own goal', $team2);
$team1_goals = $team1_goals_scored + $team2_own_goals;
echo $team1_goals;
echo ' - ';
$team2_goals_scored = countEvent($conn, $match_id, 'goal', $team2);
$team1_own_goals = countEvent($conn, $match_id, 'own goal', $team1);
$team2_goals = $team2_goals_scored + $team1_own_goals;
echo $team2_goals;
echo '<input type="submit" value="Select" name="'.$match_id.'">'. $status .'<br/>';
$i++;
}
?>
</form>
</body>
</html>