title: How to limit Pagination with Search from Mysqli on this code php?
body: <p>i tried 2 month for this code i try modify output limit pagination
  but not work for me every time</p>
  
  <pre><code>&lt;?php
                          ini_set( 'display_errors', 1 );
                          error_reporting( ~0 );
  
                          $strKeyword = null;
  
                          if ( isset( $_POST["txtKeyword"] ) ) {
                              $strKeyword = $_POST["txtKeyword"];
                          }
                          if ( isset( $_GET["txtKeyword"] ) ) {
                              $strKeyword = $_GET["txtKeyword"];
                          }
                          ?&gt;
  
   include( 'condb.php' );
                              $sql      = "SELECT *FROM an_files WHERE (f_episode LIKE '%" . $strKeyword . "%' or f_name LIKE '%" . $strKeyword . "%')";
                              $query    = mysqli_query( $con, $sql );
                              $num_rows = mysqli_num_rows( $query );
                              $per_page = 5;   // Per Page
                              $page     = 1;
  
                              if ( isset( $_GET["Page"] ) ) {
                                  $page = $_GET["Page"];
                              }
  
                              $prev_page = $page - 1;
                              $next_page = $page + 1;
  
                              $row_start = ( ( $per_page * $page ) - $per_page );
                              if ( $num_rows &lt;= $per_page ) {
                                  $num_pages = 1;
                              } else if ( ( $num_rows % $per_page ) == 0 ) {
                                  $num_pages = ( $num_rows / $per_page );
                              } else {
                                  $num_pages = ( $num_rows / $per_page ) + 1;
                                  $num_pages = (int) $num_pages;
                              }
                              $row_end = $per_page * $page;
                              if ( $row_end &gt; $num_rows ) {
                                  $row_end = $num_rows;
                              }
  
                              $sql   .= "ORDER BY f_date DESC LIMIT $row_start ,4 ";
                              $query = mysqli_query( $con, $sql );
  
               &lt;form class="form-search" action="&lt;?php echo $_SERVER['SCRIPT_NAME']; ?&gt;" method="post"&gt;
                                  &lt;table border="0" align="right" width="100%"&gt;
                                      &lt;tr&gt;
                                          &lt;td style="border: hidden; text-align: right"&gt;
                                              &lt;input placeholder="Searth" type="text"
                                                     class="input-medium search-query" name="txtKeyword" id="txtKeyword"&gt;
                                              &lt;button type="submit" class="btn"&gt;Search&lt;/button&gt;
                                          &lt;/td&gt;
                                      &lt;/tr&gt;
                                  &lt;/table&gt;
                              &lt;/form&gt;
  
    &lt;div class="pagination"&gt;
  
                                              &lt;?php
                                              if ( $prev_page ) {
                                                  echo " &lt;a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&amp;txtKeyword=$strKeyword'&gt;&lt;&lt; Back&lt;/a&gt; ";
                                              }
  
                                              for ( $i = 1; $i &lt;= $num_pages; $i ++ ) {
                                                  if ( $i != $page ) {
                                                      echo "&lt;a  href='$_SERVER[SCRIPT_NAME]?Page=$i&amp;txtKeyword=$strKeyword'&gt;$i&lt;/a&gt; ";
                                                  } else {
                                                      echo "&lt;a class='active'&gt;&lt;b&gt; $i  &lt;/b&gt;&lt;/a&gt;";
                                                  }
                                              }
  
  
                                              if ( $page != $num_pages ) {
                                                  echo " &lt;a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&amp;txtKeyword=$strKeyword'&gt;Next&gt;&gt;&lt;/a&gt; ";
                                              }
                                              ?&gt;
                                          &lt;/div&gt;
  </code></pre>
  
  <p>this out out 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20</p>
  
  <p>i want out put 1 2 3 4 5 6 7 8 9 10...20</p>
  
  <p>how can i modify this code thank you</p>