-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresults.php
86 lines (82 loc) · 3.15 KB
/
results.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
<?php
require_once('login_detail.php');
require_once('common_functions.php');
// Get locations
$connection = createConnection($GLOBALS['hostname'],$GLOBALS['database'], $GLOBALS['username_db'],$GLOBALS['password_db']);
$sql = "SELECT DISTINCT location FROM donor";
$result = $connection->query($sql);
if (!$result) die($connection->error);
elseif ($result->num_rows) {
$i = 0;
$rows = array();
while($row = $result->fetch_array(MYSQLI_NUM)) {
$rows[$i] = $row[0];
$i = $i + 1;
}
$location_array = json_encode($rows);
$result->close();
}
$connection->close();
// Get food
if($_SERVER["REQUEST_METHOD"] == "POST") {
$location = sanitizeString($_POST['location']);
$connection = createConnection($GLOBALS['hostname'],$GLOBALS['database'], $GLOBALS['username_db'],$GLOBALS['password_db']);
$sql_location = mysql_entities_fix_string($connection, $location);
$sql = "SELECT d.username, d.location, f.foodPic, f.description FROM foodlist f, donor d WHERE f.donorid=d.userid && d.location = '$sql_location'";
$result = $connection->query($sql);
if (!$result) die($connection->error);
elseif ($result->num_rows) {
$i = 0;
$rows = array();
while($row = $result->fetch_array(MYSQLI_NUM)) {
$rows[$i] = $row;
$i = $i + 1;
}
$json_array = json_encode($rows);
$result->close();
}
else {
$location = "No food found!";
$json_array = "[]";
}
$connection->close();
} else {
$location = "Enter a location!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Access</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/awesomplete.css">
<script>
const locationArray = <?php echo $location_array; ?>;
const initialResults = <?php echo $json_array; ?>;
</script>
<script src="assets/js/awesomplete.js"></script>
<script src="assets/js/results.js"></script>
<script src="assets/js/locationinput.js"></script>
</head>
<body id="results-body">
<?php include("assets/includes/header.html");?>
<div class="container mt-5 pt-4">
<div class="row">
<div class="col text-center">
<form class="form-inline mb-4 mx-auto" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" onsubmit="return validate(this)" style="max-width:600px;">
<input class="form-control w-100" type="search" id="location" name="location" value="<?php echo $location; ?>" aria-label="Search">
<input type="submit" value="Search" class="btn btn-outline-primary w-25">
</form>
<h3>Results near <b>"<?php echo $location; ?>"</b></h3>
<p>Found <span id="result-num"></span> results!</p>
</div>
</div>
<div class="row">
<div class="col mx-auto px-0" style="max-width:600px;" id="result-wrap">
</div>
</div>
</div>
</body>
</html>