-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchRecipes.php
101 lines (69 loc) · 2.31 KB
/
searchRecipes.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
99
100
101
<?php
include 'header.php';
include 'database.php';
?>
<body>
<div class="container">
<div class="row">
<div class="col-md-4">
<a href="index.php">Etusivulle</a>
</div>
<div class="col-md-4">
<div class="jumbotron">
</div>
</div>
<div class="col-md-4">
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form id="searchForm" class="" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="form-group">
<input class="form-control" type="text" name="searchRecipeName" value="">
</div>
</form>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<button class="btn btn-primary btn-block btn-search" type="submit" name="button" form="searchForm">hae</button>
</div>
<div class="col-md-4">
</div>
</div>
</div>
<div class="col-md-4">
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$search = $_POST['searchRecipeName'];
$search2 = '%' . $search . '%';
$sql = "SELECT * from recipe where recipe_name like '$search2'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo '<a class="btn btn-outline-primary btn-block btn-recipe" href="recipe.php?id=' . $row['recipe_id'] . '">' . $row['recipe_name'] . '</a>' . '<br>';
}
}else {
echo "0 results";
}
}
?>
</div>
<div class="col-md-4">
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>