title: Pagination for search page
body: <p>I want to make a pagination for search results. I can see the results in first page when I use the search box but I can't see the other results in other pages. What am I doing wrong?</p>
  <p>I would be really glad if you could help me</p>
  <p>Here' my search page codes.</p>
  <p>Codes for pagination</p>
  <pre><code>&lt;?php
      
                  if(isset($_GET[&quot;page&quot;])) {
                      $page = $_GET[&quot;page&quot;];
                  }else {
                      
                      $page = &quot;&quot;;
                  }
  
              if($page == &quot;&quot; || $page == 1) {
                  
                  $starter_post = 0;
              } else {
                  
                  $starter_post = ($page * 6) - 6;
              }
      
                      $sql_query2 = &quot;SELECT * FROM posts &quot;;
                      $look_all_post = mysqli_query($conn, $sql_query2);
                      $all_post_count = mysqli_num_rows($look_all_post);
                      $page_number = ceil ($all_post_count / 6);
  
  </code></pre>
  <p>Codes for search results</p>
  <pre><code> 
      if(isset($_POST[&quot;searchbtn&quot;])) {
          
          $search = $_POST[&quot;search&quot;];
          
          
          $query = &quot;SELECT * FROM posts WHERE post_tags LIKE '%$search%' ORDER BY post_id DESC LIMIT $starter_post, 6&quot;;
          $search_query = mysqli_query($conn, $query);
          
          if(!$search_query) {
              die(&quot;QUERY FAILED:&quot;. mysqli_error($conn));
          }
          
          $search_count = mysqli_num_rows($search_query);
          
          if($search_count == 0) {
              echo &quot;&lt;h3&gt; No Result &lt;/h3&gt;&quot;;
          } else {
              
                   
                              
                              while ($row = mysqli_fetch_assoc($search_query)){
                                  $post_id = $row[&quot;post_id&quot;];
                                  $post_date = $row[&quot;post_date&quot;];
                                  $date = strtotime($post_date);
                                  $newdate = date(&quot;d/m/Y&quot;, $date);
                                  $post_title = $row[&quot;post_title&quot;];
                                  $post_text = $row[&quot;post_text&quot;];
                                  $post_image = $row[&quot;post_image&quot;];
                                  
                                         
                          ?&gt;
                                  
                &lt;div class=&quot;col-md-6&quot;&gt;
                    &lt;div class=&quot;blog&quot;&gt;
                       &lt;div class=&quot;blog-img &quot;&gt;
                          &lt;img src=&quot;images/&lt;?php echo $post_image; ?&gt;&quot; class=&quot;img-fluid&quot; &gt;
                          &lt;/div&gt;
                              &lt;div class=&quot;blog-content&quot;&gt;
                                  &lt;ul class=&quot;blog-meta&quot;&gt;
                                     &lt;li&gt;&lt;i class=&quot;far fa-calendar-alt&quot;&gt;&lt;/i&gt;&lt;span class=&quot;writer&quot;&gt;&lt;?php 
                                     echo $newdate; ?&gt;&lt;/span&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                                      &lt;h3&gt;&lt;?php echo $post_title; ?&gt;&lt;/h3&gt;
                                      &lt;p&gt;&lt;?php echo $post_text; ?&gt;&lt;/p&gt;
                                      &lt;div class=&quot;blog-content2 text-center&quot;&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;   
                              &lt;/div&gt;
                          &lt;/div&gt;
                                  
                                  
                            &lt;?php } 
                                       
              
              
          }
          
      }
                          ?&gt;
        
  </code></pre>
  <p>Codes for pagination</p>
  <pre><code>        
              &lt;/div&gt;
                      
     &lt;div class=&quot;row&quot;&gt;
   &lt;nav aria-label=&quot;Page navigation example&quot;&gt;
    &lt;ul class=&quot;pagination justify-content-center&quot;&gt;
   &lt;li &lt;?php if ($page == 1 or $page == &quot;&quot;) {echo &quot;class='page-item disabled'&quot;;} ?&gt;&gt;
     &lt;a class=&quot;page-link&quot; href=&quot;search.php?page=&lt;?php if ($page &gt; 1) {echo $page - 1;} ?&gt;&quot;&gt;Previous&lt;/a&gt;
   &lt;/li&gt;
    &lt;?php //Pagination Continue
     for($i=1; $i&lt;=$page_number; $i++) {
      echo &quot;&lt;li class='page-item'&gt;&lt;a class='page-link' href='search.php?page=$i'&gt;{$i}&lt;/a&gt;&lt;/li&gt;&quot;;
     }    
    ?&gt;
   &lt;li &lt;?php if ($page == $page_number) {echo &quot;class='page-item disabled'&quot;;} ?&gt;&gt;
     &lt;a class=&quot;page-link&quot; href=&quot;search.php?page=&lt;?php if ($page == &quot;&quot;) {echo $page = 2;} else if($page_number!=$page){echo $page+1;} else if($page_number==$page){echo $page;}?&gt;&quot;&gt;Next&lt;/a&gt;
   &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/nav&gt;
  &lt;/div&gt; 
  
  </code></pre>