Advertisement
Guest User

resultpage

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. set_time_limit(60);
  5.  
  6. const included = true;
  7.  
  8. require_once "inc/helpers.inc.php";
  9. require_once "inc/setup_database.inc.php";
  10. require_once "inc/search.inc.php";
  11.  
  12. $get = $_GET; // shorthand access
  13. if (!isset($get['q']) || $get['q'] === "") {
  14. header("Location: ../homepage.php");
  15. }
  16.  
  17. // search query
  18. $query = $conn->escape_string($get['q']);
  19.  
  20. // index to start at (pagination)
  21. $startAt = isset($get['start']) ? $get['start'] : 1;
  22. $startAt = ($startAt - 1) * 10;
  23.  
  24. // search db
  25. $results = search($conn, "$query", $startAt); // returns [result, query time, totalRows] or null
  26.  
  27. if (is_array($results)) {
  28. $searchResult = $results[0];
  29. $queryTime = $results[1];
  30. $totalRows = $results[2];
  31. }
  32.  
  33. ?>
  34.  
  35. <!DOCTYPE html>
  36. <html lang="en">
  37. <head>
  38. <meta charset="utf-8">
  39. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  40. <meta name="viewport" content="width=device-width, initial-scale=1">
  41.  
  42. <title><?php echo $query." - " ?> cu_searchengine search</title>
  43.  
  44. <link rel="icon" href="../assets/images/favicon.ico">
  45. <link href="../assets/css/bootstrap.min.css" rel="stylesheet">
  46. <link href="../assets/css/styles.min.css" rel="stylesheet">
  47.  
  48. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  49. <!--[if lt IE 9]>
  50. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  51. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  52. <![endif]-->
  53. </head>
  54. <body>
  55.  
  56. <nav style="position: relative; margin-bottom: 10px;" class="navbar navbar-default navbar-fixed-top">
  57. <div style="padding-left: 0;" class="container">
  58.  
  59. <div class="row">
  60. <div class="col-md-10">
  61. <div class="navbar-header">
  62. <a class="navbar-brand" href="./../homepage.php">
  63. <img width="110" height="27" src='../assets/images/cu_searchengine2.png'/>
  64. </a>
  65. </div>
  66.  
  67. <div id="navbar" class="collapse navbar-collapse">
  68. <form action="./resultpage.php" class="form-inline">
  69. <div class="form-group">
  70. <input value="<?php echo $query; ?>" name="q" type="search" style="width: 400px;" class="form-control box input-lg" id="search_box">
  71. <button type="submit" class="btn btn-primary" style="padding-top: 8px; padding-bottom: 8px;">search</button>
  72. </div>
  73. </form>
  74. </div><!--/.nav-collapse -->
  75. </div>
  76.  
  77. </div>
  78.  
  79. </div>
  80. </nav>
  81.  
  82.  
  83. <div class="container" style="width: 631px; margin-left: 17.3%;">
  84.  
  85. <?php
  86. if (!$results) {
  87. noResult();
  88. } // no result
  89.  
  90. else {
  91. displayResults($searchResult);
  92. }
  93. ?>
  94.  
  95. <?php
  96. function displayResults($data)
  97. {
  98. global
  99. $queryTime,
  100. $query,
  101. $totalRows,
  102. $startAt;
  103.  
  104. if ($startAt === 0) {
  105. echo "<small class='results-count'> $totalRows Result(s) (".round($queryTime, 2)." seconds) </small> <br><br>";
  106. } else {
  107. echo "<small> $totalRows Result(s) (".round($queryTime, 2)." seconds) </small> <br>
  108. <small class='results-count'> Page ".(($startAt/10) + 1)." </small> <br><br>";
  109. }
  110.  
  111. while ($row = $data->fetch_row()) {
  112. $query_id = $row[0];
  113. $query = $row[1];
  114. $query_ans = $row[2];
  115. $title = $query;
  116. $content = $query_ans;
  117. $url = "localhost/cu_searchengine?res=".$query_id."_".urlencode($title);
  118.  
  119. $displayContent = getDisplayContent($content, $query); // filter content to get parts with our query
  120. ?>
  121. </b></b></b>
  122. <a class='result-link' href='<?php echo $url ?>'> <span style="font-size: 18px;"> <?php echo $title ?> </span> </a>
  123. <div>
  124. <span class='result-content'> <?php echo substr($displayContent, 0, 250) ?> ...</span>
  125. </div>
  126. <br>
  127. <?php
  128.  
  129. }
  130.  
  131. // display pagination
  132. displayPaging($totalRows);
  133. }
  134.  
  135.  
  136. function noResult()
  137. {
  138. ?>
  139.  
  140. <!-- no result -->
  141. <h3> Your search - <b> <?php echo htmlentities($GLOBALS['query']); ?> </b> - did not match any document </b> </h3>
  142. <br>
  143. <p> None of the indexed pages contains your search query. </p>
  144.  
  145. <?php
  146.  
  147. }
  148.  
  149. ?>
  150.  
  151. <br>
  152. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement