title: Display Search Result with Pagination using php and mysql
body: <p>I have a search text box., if i search any terms for ex: PHP, html 
  it will display a results .</p>
  
  <p>now what i need is to display with a pagination pages like 1 2 3 4 5 like that </p>
  
  <p>Im wasting 3days on it i tried myself a lot but no use 
  i dono were i going wrong </p>
  
  <p>no errors are coming no next page is going displays record of first 2 results </p>
  
  <p>need to fetch next results on next page means page2 , 3 like that end of the result says last page.
  kindly help me on it .. my code is below</p>
  
  <pre><code>&lt;?php
  require('../connect.php');
  $rec_limit = 2;
  if (isset($_GET['search']))
  {
  $searchtext= $_GET['searchtext'];
  }
  $sql = "SELECT * from jobpost WHERE jobtitle LIKE '%$searchtext%' LIMIT 2";
  mysqli_select_db($con, 'login');
  $result= mysqli_query($con, $sql);
  if(!$result)
  {
  echo "error";
  }   
  if(mysqli_num_rows($result) &gt;0){
  echo "Your Search Term : $searchtext ";
  echo"&lt;br&gt;";
  while($row = $result-&gt;fetch_assoc())        
  {
  
      echo "&lt;table&gt;";
      echo "&lt;tr&gt; &lt;td&gt;Job Title:&lt;/td&gt; &lt;td&gt;{$row['jobtitle']} &lt;/td&gt;      
   &lt;/tr&gt;".
          "&lt;tr&gt; &lt;td&gt;Job Description: &lt;/td&gt; &lt;td&gt;  
    {$row['jobdescription']}&lt;/td&gt; &lt;/tr&gt; ".
          "&lt;br&gt;";
      echo "&lt;/table&gt;"; 
  
  } 
  }
  else{
      echo "Your Search Term : $searchtext ";
      echo "&lt;br&gt;";
      echo "no results found";
  }
  // pagination
  $row = mysqli_fetch_array($result, MYSQL_NUM );
  $rec_count = $row[0];
  if( isset($_GET{'page'} ) )
  {
  $page = $_GET{'page'} + 1;
  $offset = $rec_limit * $page ;
  }
  else
  {
  $page = 0;
  $offset = 0;
  }
  $left_rec = $rec_count - ($page * $rec_limit);
  $data = mysqli_query($con, "SELECT * FROM jobpost WHERE jobtitle LIKE     
  '%$searchtext%' LIMIT $offset, $rec_limit") or die(mysqli_error());
  if(mysqli_num_rows($data) &gt;0){
  while($row = mysqli_fetch_array($data)) 
  {
      /*echo "&lt;table&gt;";
      echo "&lt;tr &gt; &lt;td&gt;Job Title:&lt;/td&gt; &lt;td&gt;{$row['jobtitle']} &lt;/td&gt;     
  &lt;/tr&gt;".
          "&lt;tr &gt; &lt;td&gt;Job Description: &lt;/td&gt; &lt;td&gt;        
  {$row['jobdescription']}&lt;/td&gt; &lt;/tr&gt; ".
          "&lt;br&gt;";
      echo "&lt;/table&gt;"; */
  }
  }
  
  else{
  echo"&lt;a href='search.php?searchtext=$searchtext&amp;search=search'&gt;No images     
  available click here for Home &lt;/a&gt;";
  }
  if( $page &gt; 0 )
  {
  $last = $page - 2;
  echo "&lt;br&gt;";
  echo "&lt;a href=\"search.php?searchtext=$searchtext&amp;search=search=$last\"      
  &gt;Last 2 Records&lt;/a&gt; |";
  echo "&lt;a href=\"search.php?searchtext=$searchtext&amp;search=search=$page\"               
  &gt;Next 2 Records&lt;/a&gt;";
  }
  else if( $page == 0 )
  {
  echo "&lt;br&gt;";
  echo "&lt;a href=\"search.php?searchtext=$searchtext&amp;search=search=$page\"      
  &gt;1&lt;/a&gt;";
  }
  else if( $left_rec &lt; $rec_limit )
  {
  $last = $page - 2;
  echo "&lt;br&gt;";
  echo "&lt;a href=\"search.php?searchtext=$searchtext&amp;search=search=$last\"   
  &gt;2&lt;/a&gt;";
  }
  mysqli_close($con);
  ?&gt;
  </code></pre>
  
  <p>kindly help me..</p>
  
  <p>i just want to search any input in a text box and display it in a pagination its my need.</p>