Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. <?php
  2. include("functions.php");
  3. include("header.php");
  4. include("navigation.php");
  5. ?>
  6.  
  7. <div id="maincontainer">
  8.  
  9. <div id="main">
  10.  
  11. <div id="header">
  12. <h1>Our Services</h1>
  13. </div>
  14.  
  15. <?php
  16.  
  17. if(isset($_GET['search'])) {
  18. $searchString = $_GET['search'];
  19. }
  20. else {
  21. $searchString = "";
  22. }
  23.  
  24. $safeSearchString = htmlspecialchars($searchString, ENT_QUOTES,"UTF-8");
  25.  
  26. if(isset($_GET['page'])){
  27. $currentPage = intval($_GET['page']);
  28. } else {
  29. $currentPage = 0;
  30. }
  31.  
  32. if(isset($_GET['category']))
  33. {
  34. $categoryFilter = $_GET['category'];
  35. }
  36. else
  37. {
  38. $categoryFilter = '%';
  39. }
  40.  
  41. $dbh = connectToDatabase();
  42.  
  43.  
  44. // 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.
  45. echo "<form>";
  46. echo "<input name = 'search' type = 'text'/>";
  47. echo "<input type = 'submit'/>";
  48. echo "</form>";
  49. echo "<br />";
  50.  
  51. $SqlSearchString = "%$safeSearchString%";
  52.  
  53. $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 ?;');
  54. $statement->bindValue(1, $SqlSearchString);
  55. $statement->bindValue(2, $SqlSearchString);
  56. $statement->bindValue(3, $categoryFilter);
  57. $statement->bindValue(4, $currentPage * 5);
  58. // TODO: put any required binding value here
  59.  
  60. $statement->execute();
  61.  
  62. while($row = $statement->fetch())
  63. {
  64. $serviceID = makeOutputSafe($row['serviceID']);
  65. $serviceName = makeOutputSafe($row['serviceName']);
  66. $serviceDescription = makeOutputSafe($row['serviceDescription']);
  67.  
  68.  
  69. echo "<div class = 'serviceBox'>";
  70. echo "<a href='viewService.php?serviceID=$serviceID'><img src ='images/service/$serviceID.jpg'alt ='Services'></a>";
  71. echo "<p><b>$serviceName</b><br/>";
  72. echo "<small>$serviceDescription</small><br/>";
  73.  
  74. echo "<small>Category: </small>";
  75. // TODO: echo service details here, including service's image, name and description.
  76.  
  77.  
  78.  
  79. // 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.
  80.  
  81. $statemnetCatServices = $dbh->prepare('SELECT categoryName FROM ServiceCategory WHERE serviceID =?');
  82. $statementCatServices->bindValue(1, $serviceID);
  83. $statementCatServices->execute();
  84.  
  85. while ($rowCatServices = $statementCatServices->fetch())
  86. {
  87. $categoryName = makeOutputSafe($rowCatServices['categoryName']);
  88. echo "<small><i>$categoryName</i></small>";
  89. }
  90. echo "</p>";
  91. echo "</div> \n";
  92.  
  93. }
  94. echo "<br />";
  95.  
  96. if ($currentPage > 0)
  97. {
  98. $previousPage = $currentPage - 1;
  99. echo "<a href = 'serviceList.php?page=$previousPage&search=$categoryFilter'><small> [Previous Page] </small></a>";
  100. }
  101.  
  102. $nextPage = $currentPage + 1;
  103. echo "<a href = 'serviceList.php?page=$nextPage&search=$safeSearchString=$categoryFilter'><small [Next page] </small></a>";
  104. //TODO: create pagination links (nextpage and previouspage) here.
  105.  
  106. ?>
  107. </div>
  108. </div>
  109.  
  110. <?php
  111. include("footer.php");
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement