-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
83 lines (80 loc) · 2.25 KB
/
search.php
File metadata and controls
83 lines (80 loc) · 2.25 KB
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
<?php
require_once "templates/page_setup.php";
$title = "Search";
$page_name = "search";
include "templates/header.php";
$current_tab = "comment_rating";
$current_page = 1;
$num_per_page = 25;
include "templates/jumbotron.php";
?>
<main>
<div class = "container">
<div class = "row">
<div class = "col-sm-3">
</div>
<div class = "col-sm-9">
<div class = "header">
<h2>Search for your favorite ingredient</h2>
</div>
<?php
if(isset($_GET['search']) and !empty($_GET['search']) ):
$tab_urls = Utils::removeParameterFromUrl("b");
$tab_urls = Utils::makeSureURLisQueryString($tab_urls);
?>
<?php
$db = new Database();
$query_term = strip_tags($_GET['search']);
$num_of_results = $db->getNumberOfResults($query_term);
$offset = $num_per_page*($current_page-1);
$ingredients = $db->searchForResults($query_term);
$max_pages = ceil($num_of_results/$num_per_page);
?>
<div class = "pull-left" style = "padding:20px;">Showing search results for <b><?php echo strip_tags($_GET['search']);?></b> (total of <?php echo $num_of_results;?>)
</div>
<?php
if($num_of_results==0):
echo "<p class = \"clear-all\" We did not find any results for the term <b>$query_term</b>";
else:
?>
<nav class = "pull-right">
</nav>
<table class="table table-condensed table-striped clear-all">
<!-- defines the header of a table -->
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
foreach ($ingredients as $ingredient){ ?>
<tr>
<td><?php echo $ingredient->name ?></td>
<td><?php echo $ingredient->price ?></td>
<td><?php echo $ingredient->description ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<nav class="pull-right">
</nav>
<?php
endif;
endif;
?>
</div>
</div>
</div>
<?php
if(empty($_GET['search'])){
echo '<b>You searched for nothing!</b>';
echo '<p>Check out all of our <a href="products_listing.php">products</a> here!</p>';
}
?>
</main>
<?php include "templates/footer.php";?>