title: I want to add pagination in my script
body: <p>my problem:---<img src="https://i.stack.imgur.com/5MCBF.png" alt="enter image description here"></p>
  
  <p>This is my wifi_log.php file</p>
  
  <pre><code>    &lt;?php // find out how many rows are in the table 
  $sql = "SELECT COUNT(*) FROM log_wifi";
  $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
  $r = mysql_fetch_row($result);
  $numrows = $r[0];
  
  // number of rows to show per page
  $rowsperpage = 10;
  // find out total pages
  $totalpages = ceil($numrows / $rowsperpage);
  echo $resultpage= $_GET['results_page'];
  // get the current page or set a default
  if (isset($_GET['currentpage']) &amp;&amp; is_numeric($_GET['currentpage'])) {
     // cast var as int
     $currentpage = (int) $_GET['currentpage'];
  } else {
     // default page num
     $currentpage = 1;
  } // end if
  
  
  // if current page is greater than total pages...
  if ($currentpage &gt; $totalpages) {
     // set current page to last page
     $currentpage = $totalpages;
  } // end if
  
  // if current page is less than first page...
  if ($currentpage &lt; 1) {
     // set current page to first page
     $currentpage = 1;
  } // end if
  
  // the offset of the list, based on current page 
  $offset = ($currentpage - 1) * $rowsperpage;
  
  // get the info from the db 
  $sql = "SELECT * FROM log_wifi LIMIT $offset, $rowsperpage";
  $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
  ?&gt;
  </code></pre>
  
  <p>My data displaying here:=</p>
  
  <pre><code>&lt;?php
  
   //while there are rows to be fetched...
  while ($row = mysql_fetch_assoc($result))
   {
     ?&gt;
      &lt;td&gt;&lt;?php echo $row['id']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['user_id']?&gt;&lt;/td&gt;                                       
      &lt;td&gt;&lt;?php echo $row['imei']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['time_stamp']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['sending_time']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['RSSI']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['BSSID']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['SSID']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['sleep_time_start']?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row['sleep_time_end']?&gt;&lt;/td&gt;
      &lt;/tr&gt;           
     &lt;?php
  } //// end while
  ?&gt;
  </code></pre>
  
  <p>Here is my pagination like FIRST &lt;&lt; 1 2 3 >> LAST-->this is working properly</p>
  
  <pre><code>&lt;tr&gt;&lt;th id="footer" colspan="10"&gt;
  
      &lt;?php 
      /******  build the pagination links ******/
  // range of num links to show
  $range = 3;
  if($currentpage==1)
  {
      echo '&lt;span class="prn"&gt;  First &amp;lt;&amp;lt;&lt;/span&gt;&amp;nbsp;';
  } 
  if ($currentpage &gt; 1) {
     // show &lt;&lt; link to go back to page 1
     echo " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=1&amp;result_page=$resultpage'&gt;First&lt;/a&gt; ";
     // get previous page num
     $prevpage = $currentpage - 1;
     // show &lt; link to go back to 1 page
     echo " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&amp;result_page=$resultpage'&gt;&lt;&lt;/a&gt; ";
  } // end if 
  
  // loop to show links to range of pages around current page
  for ($x = ($currentpage - $range); $x &lt; (($currentpage + $range) + 1); $x++) {
     // if it's a valid page number...
     if (($x &gt; 0) &amp;&amp; ($x &lt;= $totalpages)) {
        // if we're on current page...
        if ($x == $currentpage) {
           // 'highlight' it but don't make a link
           echo " &lt;b&gt;$x&lt;/b&gt; ";
        // if not current page...
        } else {
           // make it a link
           echo " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$x&amp;result_page=$resultpage'&gt;$x&lt;/a&gt; ";
        } // end else
     } // end if 
  } // end for
  
  // if not on last page, show forward and last page links        
  if ($currentpage != $totalpages) {
     // get next page
     $nextpage = $currentpage + 1;
      // echo forward link for next page 
     echo " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&amp;result_page=$resultpage'&gt;&gt;&lt;/a&gt; ";
     // echo forward link for lastpage
     echo " &lt;a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&amp;result_page=$resultpage'&gt;Last&lt;/a&gt; ";
  } // end if
  else
  {
      echo '&lt;span class="prn"&gt; Last &amp;gt;&amp;gt;&lt;/span&gt;&amp;nbsp;';
  }
  /****** end build pagination links ******/
  
  ?&gt;
  </code></pre>
  
  <p>Problem is here how to do that i know</p>
  
  <pre><code>&lt;form action="./wifi_log.php" method="get"&gt;
     &lt;select name="results_page" id="results_page" onchange="this.form.submit();" &gt;
          &lt;option value="5" NO &gt;5&lt;/option&gt;
          &lt;option value="10" SELECTED &gt;10&lt;/option&gt;
          &lt;option value="20" NO&gt;20&lt;/option&gt;
          &lt;option value="50" NO &gt;50&lt;/option&gt;
      &lt;/select&gt;       
       results per page
  &lt;/form&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;            
  </code></pre>
  
  <p>
  </p>