-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
98 lines (83 loc) · 3.22 KB
/
search.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
<?php
$mysqli = require __DIR__ . "/db.php";
$arr;
if ($_SERVER["REQUEST_METHOD"] === "GET" && !empty($_GET["note"])) {
$term = $mysqli->real_escape_string($_GET["note"]);
try {
$sql =
"SELECT * FROM notes WHERE (title LIKE '%" . $term . "%' OR body LIKE '%" . $term . "%')";
$res = $mysqli->query($sql);
$arr = $res->fetch_all();
} catch (Exception $e) {
die($mysqli->error . " " . $mysqli->errno);
}
} elseif ($_SERVER["REQUEST_METHOD"] === "GET" && !empty($_GET["tag"])) {
$term = $mysqli->real_escape_string($_GET["tag"]);
try {
$sql =
"SELECT * FROM notes WHERE tag LIKE '%" . $term . "%'";
$res = $mysqli->query($sql);
$arr = $res->fetch_all();
} catch (Exception $e) {
die($mysqli->error . " " . $mysqli->errno);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Search</title>
<style>
a {
text-decoration: none;
color: black;
}
body {
background-color: #ccd5ae;
}
div.card:hover {
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15) !important;
}
input[type="submit"] {
margin: 1rem 0 !important;
}
</style>
</head>
<body>
<div class="mx-auto pt-5" style="max-width:700px">
<h1>Search results for "<?= $term ?>"</h1>
<?php if ($res->num_rows === 0) : ?>
<img src="./Humaaans - Sitting.png" class="rounded mx-auto " alt="No notes found for the search term">
<h5 class="my-4"> No results are found. Try again with a different term</h5> <?php else : ?>
<?php foreach ($arr as $note) : ?>
<a href="note.php?id=<?= $note[0] ?>">
<div class="card my-4 shadow-sm" style="width:25rem;">
<div class="card-body">
<div class="d-flex justify-content-between">
<h5 class="card-title">
<?= $note[1] ?>
<?php if ($note[3] != "") : ?>
<span class="badge bg-secondary">
<?= $note[3] ?>
</span>
</h5>
<?php endif; ?>
<a href="delete.php?id=<?= $note[0] ?>">
<button type="button" class="btn-close" aria-label="Close"></button>
</a>
</div>
<div class="card-text">
<?= $note[2] ?>
</div>
</div>
</div>
</a>
<?php endforeach; ?>
<?php endif; ?>
<a href="index.php"><button class="btn btn-primary">See all Notes</button></a>
</body>
</html>