-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
71 lines (65 loc) · 1.69 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
require "header.php";
?>
<!DOCTYPE html>
<link rel="stylesheet" href="style.css">
<html lang="en">
<head>
<style>
table,
table td {
border: 1px solid #cccccc;
}
td {
height: 80px;
width: 80px;
text-align: center;
vertical-align: middle;
}
</style>
<meta charset="UTF-8">
<title>PHP Search</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2" style="margin-top: 1%;">
<div class="row">
<?php
$conn = new mysqli('localhost', 'root', '', 'flashcards');
if(isset($_GET['search'])){
$searchKey = $_GET['search'];
$sql = "SELECT * FROM subject, card WHERE subject_name LIKE '%$searchKey%' OR question LIKE '%$searchKey%' OR answer LIKE '%$searchKey%' ";
}else
$sql = "SELECT * FROM subject, card";
$result = $conn->query($sql);
?>
<form action="" method="GET">
<div class="col-md-6">
<input type="text" name="search" class='form-control' placeholder="SetName, Ques, or Answer" value=<?php echo @$_GET['search']; ?> >
</div>
<div class="col-md-6 text-left">
<button class="btn">Search</button>
</div>
</form>
<br>
<br>
</div>
<table class="table table-bordered">
<tr>
<th>Set Name</th>
<th>Question</th>
<th>Answer </th>
</tr>
<?php while( $row = $result->fetch_object() ): ?>
<tr>
<td><?php echo $row->subject_name ?></td>
<td><?php echo $row->question?></td>
<td><?php echo $row->answer ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
</div>
</div>
</body>
</html>