Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("functions.php");
- include("header.php");
- include("navigation.php");
- ?>
- <div id="maincontainer">
- <div id="main">
- <div id="header">
- <h1>Our Services</h1>
- </div>
- <?php
- if(isset($_GET['search'])) {
- $searchString = $_GET['search'];
- }
- else {
- $searchString = "";
- }
- $safeSearchString = htmlspecialchars($searchString, ENT_QUOTES,"UTF-8");
- if(isset($_GET['page'])){
- $currentPage = intval($_GET['page']);
- } else {
- $currentPage = 0;
- }
- if(isset($_GET['category']))
- {
- $categoryFilter = $_GET['category'];
- }
- else
- {
- $categoryFilter = '%';
- }
- $dbh = connectToDatabase();
- // TODO: create a form for the search feature which includes a text field for the keyword input, a drop down list for category filter, and a search button.
- echo "<form>";
- echo "<input name = 'search' type = 'text'/>";
- echo "<input type = 'submit'/>";
- echo "</form>";
- echo "<br />";
- $SqlSearchString = "%$safeSearchString%";
- $statement = $dbh->prepare('SELECT Services.serviceName, serviceDescription FROM Services WHERE (serviceName like ? OR serviceDescription LIKE ?) AND serviceID IN (SELECT serviceID FROM serviceCategory WHERE categoryName LIKE ?) LIMIT 5 OFFSET ?;');
- $statement->bindValue(1, $SqlSearchString);
- $statement->bindValue(2, $SqlSearchString);
- $statement->bindValue(3, $categoryFilter);
- $statement->bindValue(4, $currentPage * 5);
- // TODO: put any required binding value here
- $statement->execute();
- while($row = $statement->fetch())
- {
- $serviceID = makeOutputSafe($row['serviceID']);
- $serviceName = makeOutputSafe($row['serviceName']);
- $serviceDescription = makeOutputSafe($row['serviceDescription']);
- echo "<div class = 'serviceBox'>";
- echo "<a href='viewService.php?serviceID=$serviceID'><img src ='images/service/$serviceID.jpg'alt ='Services'></a>";
- echo "<p><b>$serviceName</b><br/>";
- echo "<small>$serviceDescription</small><br/>";
- echo "<small>Category: </small>";
- // TODO: echo service details here, including service's image, name and description.
- // TODO: list out categories for a particular service here. You need to create a new query, and list out retrieved categories. Use binding when necessary.
- $statemnetCatServices = $dbh->prepare('SELECT categoryName FROM ServiceCategory WHERE serviceID =?');
- $statementCatServices->bindValue(1, $serviceID);
- $statementCatServices->execute();
- while ($rowCatServices = $statementCatServices->fetch())
- {
- $categoryName = makeOutputSafe($rowCatServices['categoryName']);
- echo "<small><i>$categoryName</i></small>";
- }
- echo "</p>";
- echo "</div> \n";
- }
- echo "<br />";
- if ($currentPage > 0)
- {
- $previousPage = $currentPage - 1;
- echo "<a href = 'serviceList.php?page=$previousPage&search=$categoryFilter'><small> [Previous Page] </small></a>";
- }
- $nextPage = $currentPage + 1;
- echo "<a href = 'serviceList.php?page=$nextPage&search=$safeSearchString=$categoryFilter'><small [Next page] </small></a>";
- //TODO: create pagination links (nextpage and previouspage) here.
- ?>
- </div>
- </div>
- <?php
- include("footer.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement