-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleague.php
More file actions
68 lines (53 loc) · 1.65 KB
/
league.php
File metadata and controls
68 lines (53 loc) · 1.65 KB
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
<html>
<head>
<title>League Results (PHP)</title>
<style> table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<form method="post" action="assignment.php">
Search player name:
<input type="text" name="name">
<input type="submit" name="go" value="Go">
</form>
<?php
//Database variables
$servername = "localhost";
$username = "root";
$password = "password";
$db = "b3_assignment";
//Open new database connection
$db = new mysqli($servername, $username, $password, $db);
if ($db->connect_error) { die("Failed: ".$db->connect_error);}
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$name=$_POST['name'];
$name=mysqli_real_escape_string($db,$name);
$name=strip_tags($name);
$stmt = $db->prepare("SELECT DISTINCT p.Player_ID, p.Forename, p.Surname, p.Team, p.Status, s1.Skills FROM Player p
LEFT JOIN
(SELECT DISTINCT s.Player, GROUP_CONCAT(s.Skill) AS Skills
FROM Skill s GROUP BY s.Player) AS s1
ON s1.Player = p.Player_ID
WHERE p.Forename LIKE ? OR p.Surname LIKE ?");
$param1 = $param2 = '%'."$name".'%';
$stmt->bind_param("ss", $param1, $param2);
$stmt->execute();
$result2 = $stmt->get_result();
if ($result2->num_rows > 0)
{
echo "<table><tr><th>ID</th><th>Forename</th><th>Surname</th><th>Team</th><th>Status</th><th>Skills</th></tr>";
while($obj = mysqli_fetch_object($result2))
{
echo "<tr><td>".$obj->Player_ID."</td><td>".$obj->Forename."</td><td>".$obj->Surname."</td><td>".$obj->Team."</td><td>".$obj->Status."</td><td>".$obj->Skills. "</td></tr>";
}
echo "</table>";
mysqli_free_result($result2);
} else { echo "No matches";}
$stmt->close();
$db->close();
}
?>
</body>
</html>