-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteamstats.php
192 lines (170 loc) · 6.07 KB
/
teamstats.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
session_start(); //start session
//if not loggedin then redirect to login
if (!isset($_SESSION["userID"])) {
header("Location: login.php");
exit();
}
$host = "localhost";
$username = "root";
$password = "root";
$database = "statslam_db";
$conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$team = isset($_GET["team"]) ? $_GET["team"] : "";
$parts = preg_split('/\s+(?=\S*$)/', $team);
if ($team != "") {
$stmt = $conn->prepare(
"SELECT teamID FROM teaminfo WHERE city = ? AND name = ?"
);
$stmt->bind_param("ss", $parts[0], $parts[1]);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$teamID = $row["teamID"];
} else {
die("Team not found.");
}
$stmt = $conn->prepare("SELECT * FROM teamtotals WHERE teamID = ?");
$stmt->bind_param("i", $teamID);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$teamTotals = $result->fetch_assoc();
} else {
die("error with team totals");
}
$stmt->close();
} else {
die("Invalid team ID.");
}
if ($teamID >= 0) {
$stmt = $conn->prepare("SELECT * FROM playerinfo WHERE teamID = ?");
$stmt->bind_param("i", $teamID);
$stmt->execute();
$result = $stmt->get_result();
$teamPlayers = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$teamPlayers[] = $row;
}
} else {
die("Player not found.");
}
$stmt->close();
} else {
die("issue with players");
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/index.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($team) ?> - Stats</title>
</head>
<body>
<div class="header-container">
<h1 class="webHeader"><img src="images/basketball.png" style="width:40px;height:20px;" />StatSlam</h1>
<div class="search-container">
<form action="search.php" method="post">
<input type="text" class="search-input" name="search" placeholder="Search...">
<button type="submit" class="search-button">Search</button>
</form>
</div>
</div>
<div class="topnav">
<a href="index.php">Home</a>
<a href="allPlayers.php">Players</a>
<a href="pricing.php">Pricing</a>
<?php if (!isset($_SESSION["userID"])): ?>
<!-- if logged in, show logout -->
<a href="login.php">Login</a>
<a href="signUp.php">Sign Up</a>
<?php else: ?>
<a href="logout.php">Logout</a>
<?php endif; ?>
<a href="contact.php">Contact</a>
</div>
<div class="container">
<h1><?= htmlspecialchars($team) ?> - Stats</h1>
<p><strong>Games:</strong> <?= htmlspecialchars(
$teamTotals["games"]
) ?></p>
<p><strong>Points:</strong> <?= htmlspecialchars(
$teamTotals["points"]
) ?></p>
<p><strong>Field Goals Attempted:</strong> <?= htmlspecialchars(
$teamTotals["fieldGoalsAttempted"]
) ?></p>
<p><strong>Field Goals Made:</strong> <?= htmlspecialchars(
$teamTotals["fieldGoalsMade"]
) ?></p>
<p><strong>Field Goal Percentage:</strong> <?= htmlspecialchars(
$teamTotals["fieldGoalPercentage"]
) ?></p>
<p><strong>Two Pointers Attempted:</strong> <?= htmlspecialchars(
$teamTotals["twoPointersAttempted"]
) ?></p>
<p><strong>Two Pointers Made:</strong> <?= htmlspecialchars(
$teamTotals["twoPointersMade"]
) ?></p>
<p><strong>Two Pointer Percentage:</strong> <?= htmlspecialchars(
$teamTotals["twoPointerPercentage"]
) ?></p>
<p><strong>Three Pointers Attempted:</strong> <?= htmlspecialchars(
$teamTotals["threePointersAttempted"]
) ?></p>
<p><strong>Three Pointers Made:</strong> <?= htmlspecialchars(
$teamTotals["threePointersMade"]
) ?></p>
<p><strong>Three Pointer Percentage:</strong> <?= htmlspecialchars(
$teamTotals["threePointerPercentage"]
) ?></p>
<p><strong>Free Throws Attempted:</strong> <?= htmlspecialchars(
$teamTotals["freeThrowsAttempted"]
) ?></p>
<p><strong>Free Throws Made:</strong> <?= htmlspecialchars(
$teamTotals["freeThrowsMade"]
) ?></p>
<p><strong>Free Throw Percentage:</strong> <?= htmlspecialchars(
$teamTotals["freeThrowPercentage"]
) ?></p>
<p><strong>Offensive Rebounds:</strong> <?= htmlspecialchars(
$teamTotals["offensiveRebounds"]
) ?></p>
<p><strong>Defensive Rebounds:</strong> <?= htmlspecialchars(
$teamTotals["defensiveRebounds"]
) ?></p>
<p><strong>Assists:</strong> <?= htmlspecialchars(
$teamTotals["assists"]
) ?></p>
<p><strong>Blocks:</strong> <?= htmlspecialchars(
$teamTotals["blocks"]
) ?></p>
</div>
<div class="container">
<h1><?= htmlspecialchars($team) ?> - Players</h1>
<?php if (!empty($teamPlayers)): ?>
<ul>
<?php foreach ($teamPlayers as $player): ?>
<li>
<a href="playerstats.php?playerID=<?= urlencode(
$player["playerID"]
) ?>">
<?= htmlspecialchars($player["name"]) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>No players found for this team.</p>
<?php endif; ?>
</div>
</body>
</html>