-
Notifications
You must be signed in to change notification settings - Fork 0
/
team-stats.php
89 lines (76 loc) · 2.79 KB
/
team-stats.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Team Statistics</title>
<link rel="stylesheet" href="grid.css" />
</head>
<body>
<?php
include('header.php');
include('db-helpers.php');
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (isset($_GET['team_id'])) $stats = getTeamStats(null, $_GET['team_id']);
else {
if (isset($_GET['league_id'])) $league_id = $_GET['league_id'];
else $league_id = null;
$stats = getTeamStats($league_id, null);
}
}
?>
<div class="grid-container">
<div class="grid-header">
<h1>Team Statistics</h1>
</div>
<h6>(Click on a player's name to view their global stats)</h6>
<?php foreach ($stats as $team_stat): ?>
<div class="grid-row">
</br>
<h3><?php echo $team_stat['team_name'] ?></h3>
</br>
<table class="table table-striped table-bordered">
<tr>
<th></th>
<th>Players</th>
<th></th>
<th>Wins</th>
<th>Losses</th>
</tr>
<tr>
<td>
<h3><a class="badge badge-light" href="<?php echo "player-stats.php?id=" . $team_stat['player1_id'] ?>">
<?php echo get_player_name($team_stat['player1_id']) ?>
</a></h3>
</td>
<td>
<h3><a class="badge badge-light" href="<?php echo "player-stats.php?id=" . $team_stat['player2_id'] ?>">
<?php echo get_player_name($team_stat['player2_id']) ?>
</a></h3>
</td>
<td>
<h3><a class="badge badge-light" href="<?php echo "player-stats.php?id=" . $team_stat['player3_id'] ?>">
<?php echo get_player_name($team_stat['player3_id']) ?>
</a></h3>
</td>
<td><?php echo $team_stat['wins'] ?></td>
<td><?php echo $team_stat['losses'] ?></td>
</tr>
</table>
</div>
<?php endforeach ?>
</div>
</body>
</html>
<?php
function getTeamStats($league_id, $team_id) {
global $db;
$query = "SELECT team_name, player1_id, player2_id, player3_id, wins, losses FROM team";
if (isset($team_id)) $query = $query . " WHERE team_id = " . $team_id;
else if (isset($league_id)) $query = $query . " WHERE league_id = " . $league_id;
$query = $query . " ORDER BY wins DESC, losses";
$sql = $db->prepare($query);
$sql->execute();
$results = $sql->fetchAll();
$sql->closeCursor();
return $results;
}
?>