Note that there are some explanatory texts on larger screens.

plurals
  1. POThe first result of search term did not come out
    primarykey
    data
    text
    <p>Why always do the first result of my search term will not come out?</p> <p>I noticed that it will only appear when I navigate to the page number <code>0</code>.</p> <p>How can I solve this?</p> <p>I hope that when I navigate to page number <code>1</code>, the first result will come out too!</p> <p>PHP Code:</p> <pre><code>&lt;?php //php code goes here include 'connect.php'; // for database connection include 'script_suggestion.php'; include 'script_close_suggestion_box.php'; $query = $_GET['q']; // query $button = $_GET ['submit']; if (isset($_GET['page'])) { $page_number = (int)$_GET['page']; $page_number = mysqli_real_escape_string($page_number); } else { $page_number = 1; } $results_per_page = 10; ?&gt; </code></pre> <p>HTML Code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt; Brandon's Search Engine &lt;/title&gt; &lt;style type="text/css"&gt; #title a { font-size: 17pt; margin: 5px; padding: 2px; border-color: black; text-decoration: underline; width: 544px; } #search-result { display: block; border: 1px solid grey; border-color: grey; } #search-result:hover { background-color: #dddddd; width: 544px; } #link { font-size: 17pt; margin: 5px; padding: 2px; width: 544px; } #description { font-size: 17pt; margin: 5px; padding: 2px; width: 544px; } #search-page-number { display: block; width: auto; height: auto; border: 1px solid gray; margin: 2px; padding-left: 5px; padding-right: 5px; padding-bottom: 2px; padding-top: 2px; list-style: none; float: left; text-align: center; } #search-page-number:hover { background-color: #dddddd; } #suggestion { border: 1px solid black; visibility: hidden; position: absolute; background-color: white; z-index: 10; } #suggestion a { font-size: 12pt; color: black; text-decoration: none; display: block; width: 548px; height: auto; text-align: left; padding: 2px; } #suggestion a:hover { background-color: #dddddd; width: 544px; padding: 2px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="GET" action="search.php"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;h2&gt; Brandon's Search Engine &lt;/h2&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="text" value="&lt;?php echo htmlspecialchars($_GET['q']); ?&gt;" name="q" style="height: 27px; width: 550px; padding: 2px" name="q" onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/&gt; &lt;input type="submit" value="Search" style="height: auto; width: 60px; padding: 2px" /&gt; &lt;div id="suggestion" style="width: 548px"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br&gt; &lt;hr&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;?php //count $count_sql = "SELECT count(*) as c FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' "; $search_count = mysqli_fetch_array(mysqli_query($con,$count_sql)); $number_of_result = $search_count['c']; //SQL query $page_number = (int)$_GET['page']; $stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page"; $result = mysqli_query($con,$stmt) or die(mysqli_error($con)); //$number_of_result = mysqli_num_rows($result); if ($number_of_result &lt; 1) { echo "&lt;b&gt;No results found!&lt;/b&gt;"; echo "&lt;p&gt;"; echo "Your search - &lt;b&gt;$query&lt;/b&gt;" . " - did not match any documents. Please try different keywords."; } elseif ($number_of_result &gt; 1) { echo "&lt;b&gt;$number_of_result results found!&lt;/b&gt;"; echo "&lt;p&gt;"; //results found here and display them while (($row = \mysqli_fetch_array($result))) {//10 results per page $title = $row["title"]; $description = $row["description"]; $link = $row["link"]; echo "&lt;div id='search-result'&gt;"; echo "&lt;div id='title'&gt;&lt;a href='$link'&gt;" . $title . "&lt;/a&gt;&lt;/div&gt;"; //echo "&lt;br /&gt;"; echo "&lt;div id='link'&gt;&lt;small&gt;" . $link . "&lt;/small&gt;&lt;/div&gt;"; //echo "&lt;p&gt;"; echo "&lt;div id='description'&gt;&lt;small&gt;" . $description . "&lt;/small&gt;&lt;/div&gt;"; echo "&lt;/div&gt;"; echo "&lt;br /&gt;"; } } elseif ($number_of_result == 1) { echo "&lt;b&gt;$number_of_result result found!&lt;/b&gt;"; echo "&lt;p&gt;"; //results found here and display them while (($row = \mysqli_fetch_array($result))) {//10 results per page $title = $row["title"]; $description = $row["description"]; $link = $row["link"]; echo "&lt;div id='search-result'&gt;"; echo "&lt;div id='title'&gt;&lt;a href='$link'&gt;" . $title . "&lt;/a&gt;&lt;/div&gt;"; //echo "&lt;br /&gt;"; echo "&lt;div id='link'&gt;&lt;small&gt;" . $link . "&lt;/small&gt;&lt;/div&gt;"; echo "&lt;br /&gt;"; echo "&lt;div id='description'&gt;&lt;small&gt;" . $description . "&lt;/small&gt;&lt;/div&gt;"; echo "&lt;/div&gt;"; echo "&lt;br /&gt;"; } } ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="hidden" name="page" value="&lt;?php echo 1; ?&gt;" /&gt; &lt;div id="page-number"&gt; &lt;?php $max_page_number = ceil($number_of_result / $results_per_page); if ($number_of_result == 0) { echo " "; } elseif ($number_of_result != 0) { echo "You are on page $page_number of $max_page_number."; } //ie if 35 results are therer then we require 4 pages that are 0 to max_page_number //current page number is equal to page_number //echo $max_page_number; echo "&lt;ul&gt;"; //both the condition are not the neccesary if ($max_page_number &gt;= 1) { // if more than 2 pages if ($page_number != 1) { //First echo "&lt;li id='search-page-number'&gt;"; echo "&lt;a href=search.php?q=$query&amp;page=1&gt;First&lt;/a&gt;"; echo "&lt;/li&gt;"; } if ($page_number != 1) { //Previous echo "&lt;li id='search-page-number'&gt;"; $prev = $page_number - 1; echo "&lt;a href=search.php?q=$query&amp;page=".($prev)."&gt;Previous&lt;/a&gt;"; echo "&lt;/li&gt;"; } for($index = 1 ; $index &lt;= $max_page_number ; $index++) { echo "&lt;li id='search-page-number'&gt;"; echo "&lt;a href=search.php?q=$query&amp;page=".($index)."&gt;"; echo ($index) . "&lt;/a&gt;"; echo "&lt;/li&gt;"; } if ($page_number != $max_page_number) { //Next echo "&lt;li id='search-page-number'&gt;"; $next = $page_number + 1; echo "&lt;a href=search.php?q=$query&amp;page=".($next)."&gt;Next&lt;/a&gt;"; echo "&lt;/li&gt;"; } if ($page_number != $max_page_number) { //Last echo "&lt;li id='search-page-number'&gt;"; echo "&lt;a href=search.php?q=$query&amp;page=".($max_page_number)."&gt;Last&lt;/a&gt;"; echo "&lt;/li&gt;"; } } elseif (($max_page_number == 1 ) ) { echo "&lt;li id='search-page-number'&gt;"; echo "&lt;a href=search.php?q=$query&amp;page=1&gt;1&lt;/a&gt;"; echo "&lt;/li&gt;"; } echo "&lt;/ul&gt;"; ?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt; To insert your site in result fill in the form at &lt;a href="insert.php"&gt;here&lt;/a&gt;. &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload