-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
96 lines (93 loc) · 4.29 KB
/
admin.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
<?php
include("scripts/sessions.php");
if((isset($_SESSION['message'])) && ($_SESSION['message'] === "Authenticated"))
{
echo $_SESSION['message'];
echo "<p><a href=\"scripts/doLogout.php\">Logout</a></p>";
echo "<p><a href=\"index.php\">Home</a></p>";
if(isset($_GET["PersonDetailSearch"]))
{
$surname = $_GET['surname'];
}
else
{
$surname = "";
}
?>
<div class="flex-container">
<form action="admin.php" method="get">
<input type="input" name="surname" value="" placeholder="Surame" />
<input type="submit" value="Go" name="PersonDetailSearch" />
</form>
<a href="admin.php?surname=<?php echo $surname; ?>&PersonDetailSearch=Go&orderBy=houseNumName">Order by House Number or Name</a> |
<a href="admin.php?surname=<?php echo $surname; ?>&PersonDetailSearch=Go&orderBy=firstName">Order by First Name</a> |
<a href="admin.php?surname=<?php echo $surname; ?>&PersonDetailSearch=Go&orderBy=surname">Order by Surname</a>
<table>
<tr>
<th>First Name</th><th>Second Name</th><th>Surname</th><th>House Number or Name</th>
<th>Address One</th><th>Address Two</th><th>Address Three</th><th>Town or City</th>
<th>Post Code</th>
</tr>
<?php
if(isset($_GET["PersonDetailSearch"]))
{
include("scripts/connectDB.php");
$surname = $_GET['surname'];
//$prevPage = $_SERVER['HTTP_REFERER'];
if(isset($_GET['orderBy']))
{
$getOrder = $_GET['orderBy'];
$orderBy = "ORDER BY $getOrder";
}
else
{
$getOrder = "";
$orderBy = "";
}
if(isset($_GET['limit']))
{
$getLimit = $_GET['limit'];
$limit = "LIMIT $getLimit";
}
else
{
$limit = "LIMIT 0,3";
}
$sqlCount = "SELECT *
FROM person, address
WHERE surname LIKE '%$surname%'
AND address.addressId = person.addressID";
$result = mysqli_query($conn, $sqlCount);
$rowcount = mysqli_num_rows($result);
$countSplit = round($rowcount / 4);
$counter = 0;
while($rowcount > $counter)
{
echo "<a href=\"admin.php?surname=$surname&PersonDetailSearch=Go&orderBy=$getOrder&limit=$counter,$countSplit\">".$counter.",".$countSplit."</a> | ";
$counter = $counter + $countSplit;
}
$sql = "SELECT firstName, middleName, surname, houseNumName, addressTwo, addressThree, townCity, county, postCode
FROM person, address
WHERE surname LIKE '%$surname%'
AND address.addressId = person.addressID
$orderBy
$limit";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>".$row["firstName"]."</td><td>".$row["middleName"]."</td><td>".$row["surname"]."</td><td>".$row["houseNumName"]."</td>
<td>".$row["addressTwo"]."</td><td>".$row["addressThree"]."</td><td>".$row["townCity"]."</td><td>".$row["county"]."</td>
<td>".$row["postCode"]."</td>
</tr>";
};
}
?>
</table>
</div>
<?php
}
else
{
header("Location: index.php?error=notLoggedIn");
}
?>