/
statistics.php
198 lines (164 loc) · 8.27 KB
/
statistics.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
193
194
195
196
197
198
<?php
//connection
$link = mysqli_connect("#", "#", "#", "#") or die("Connect Error ". mysqli_error($link));
if($_POST['region'] == "sport"){
if($_POST['text'] == ''){
$sql = "SELECT * FROM sport ORDER BY leagueName ASC";
}
$sql = "SELECT * FROM sport WHERE leagueName LIKE ? ORDER BY leagueName ASC";
}
if($_POST['region'] == "team"){
if($_POST['text'] == ''){
$sql = "SELECT * FROM team ORDER BY teamName ASC";
}
$sql = "SELECT * FROM team WHERE teamName LIKE ? ORDER BY teamName ASC";
}
if($_POST['region'] == "game"){
if($_POST['text'] == ''){
$sql = "SELECT * FROM game ORDER BY gameID ASC";
}
$sql = "SELECT * FROM game WHERE (home LIKE ? OR guest LIKE ?) ORDER BY gameID ASC ";
}
function display_data($link, $sql) {
$param = "%{$_POST['text']}%";
if($_POST['region'] == "sport"){
echo "<thead>
<tr>
<th>League</th>
<th>Sports</th>
</tr>
</thead>";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "s", $param) or die("bind param");
mysqli_stmt_execute($stmt);
//show number of rows
mysqli_stmt_store_result($stmt);
$row_count = mysqli_stmt_num_rows($stmt);
printf("Number of rows: %d <br>", $row_count);
mysqli_stmt_bind_result($stmt, $leagueName, $sport);
while (mysqli_stmt_fetch($stmt)) {
echo "<form action='delete.php' method='POST'>
<input type='hidden' name='table' value='sport'>";
echo "<tr>";
//echo "<td><input class='btn btn-danger' type='submit' name='delete' value='Delete'></td>";
echo '<td><input type="hidden" name="League" value="'.$leagueName.'">'. $leagueName .'</td>';
echo '<td><input type="hidden" name="Sports" value="'.$sport.'">'. $sport .'</td>';
echo "</tr>";
echo "</form>";
}
mysqli_stmt_close($stmt);
}
}
if($_POST['region'] == "team"){
echo "<thead>
<tr>
<th></th>
<th>TeamName</th>
<th>League</th>
</tr>
</thead>";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "s", $param) or die("bind param");
mysqli_stmt_execute($stmt);
//show number of rows
mysqli_stmt_store_result($stmt);
$row_count = mysqli_stmt_num_rows($stmt);
printf("Number of rows: %d <br>", $row_count);
mysqli_stmt_bind_result($stmt, $teamName, $league);
while (mysqli_stmt_fetch($stmt)) {
echo "<form action='delete.php' method='POST'>
<input type='hidden' name='table' value='team'>";
echo "<tr>";
echo "<td><input class='btn btn-danger' type='submit' name='delete' value='Delete'></td>";
echo '<td><input type="hidden" name="TeamName" value="'.$teamName.'">'. $teamName .'</td>';
echo '<td><input type="hidden" name="League" value="'.$league.'">'. $league .'</td>';
echo "</tr>";
echo "</form>";
}
mysqli_stmt_close($stmt);
}
}
if($_POST['region'] == "game"){
echo "<thead>
<tr>
<th></th>
<th>GameID</th>
<th>Home</th>
<th>Guest</th>
<th>GameTime</th>
</tr>
</thead>";
if ($stmt = mysqli_prepare($link, $sql)) {//prepare successful
mysqli_stmt_bind_param($stmt, "ss", $param, $param) or die("bind param");
mysqli_stmt_execute($stmt);
//show number of rows
mysqli_stmt_store_result($stmt);
$row_count = mysqli_stmt_num_rows($stmt);
printf("Number of rows: %d <br>", $row_count);
mysqli_stmt_bind_result($stmt, $gameID, $home, $guest, $gameTime);
while (mysqli_stmt_fetch($stmt)) {
echo "<form action='delete.php' method='POST'>
<input type='hidden' name='table' value='game'>";
echo "<tr>";
echo "<td><input class='btn btn-danger' type='submit' name='delete' value='Delete'></td>";
echo '<td><input type="hidden" name="GameID" value="'.$gameID.'">'. $gameID .'</td>';
echo '<td><input type="hidden" name="Home" value="'.$home.'">'. $home .'</td>';
echo '<td><input type="hidden" name="Guest" value="'.$guest.'">'. $guest .'</td>';
echo '<td><input type="hidden" name="GameTime" value="'.$gameTime.'">'. $gameTime .'</td>';
echo "</tr>";
echo "</form>";
}
mysqli_stmt_close($stmt);
}
}
}
?>
<html>
<head>
<!-- I USE BOOTSTRAP BECAUSE IT MAKES FORMATTING/LIFE EASIER -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"><!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"><!-- Optional theme -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><!-- Latest compiled and minified JavaScript -->
</head>
<body>
<div class="container" align="center" >
<form action = "statistics.php" method="POST" >
<br>
<input type="text" name="text" >
<input class="btn btn-info" type="submit" name="search" value = "search">
<a class='btn btn-primary' href='main.php'>Back</a>
<br>
<?php
if($_POST['region'] == "sport"){
echo "<input type= 'radio' name= 'region' value = 'sport' checked> Sport";
}
else{
echo "<input type= 'radio' name= 'region' value = 'sport'> Sport";
}
if($_POST['region'] == "team"){
echo "<input type= 'radio' name= 'region' value = 'team' checked> Team";
}
else{
echo "<input type= 'radio' name= 'region' value = 'team'> Team";
}
if($_POST['region'] == "game"){
echo "<input type= 'radio' name= 'region' value = 'game' checked> Game";
}
else{
echo "<input type= 'radio' name= 'region' value = 'game'> Game";
}
?>
</form>
<table class="table table-hover" width= "800" border ="2" cellpadding = "2" cellspacing = "2" >
<?php
if(isset($_POST['search'])){
display_data($link, $sql);
}
?>
</table>
</div>
</body>
</html>
<?php
mysqli_close($link);
?>