title: PHP pagination - next/previous button
body: <p>I'm trying to learn PHP pagination. So far I can paginate through numbers, but previous/next buttons are appearing on the left and right of each page number, <a href="https://i.stack.imgur.com/QXJMJ.jpg" rel="nofollow noreferrer">like this</a>. </p>
  
  <p>Here is the code I am using to generate pagination:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;title&gt;PHP&lt;/title&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div class="container"&gt;
    &lt;h2&gt;List Of Customers&lt;/h2&gt;
  
  &lt;div class="row"&gt;   
  
      &lt;a href="add.php" class="btn btn-success"&gt;Create&lt;/a&gt;
  
    &lt;table class="table table-bordered"&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Last Name&lt;/th&gt;
          &lt;th&gt;Address&lt;/th&gt;
          &lt;th&gt;Phone&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Action&lt;/th&gt;  
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  
  
  &lt;?php
  
  include 'db.php';
  
  
  $link = db_connect();
  
  
  
  $limit = 4; 
  
  
      if (isset($_GET["page"] )) 
          {
          $page  = $_GET["page"]; 
          } 
      else 
         {
          $page=1; 
         };  
  
  $record_index= ($page-1) * $limit;      
  
  
  
  
  
  
   $sql = "SELECT * FROM student_form LIMIT $record_index, $limit";
  
     $retval = mysqli_query($link, $sql);
  //  print_r($retval);
  
  
     if (mysqli_num_rows($retval) &gt; 0) {
  
           while($row = mysqli_fetch_assoc($retval)) {
  
          echo '&lt;tr&gt;';
  
                              echo '&lt;td&gt;'. $row['first_name'] . '&lt;/td&gt;';
                              echo '&lt;td&gt;'. $row['last_name'] . '&lt;/td&gt;';
                              echo '&lt;td&gt;'. $row['address'] . '&lt;/td&gt;';
                              echo '&lt;td&gt;'. $row['phone'] . '&lt;/td&gt;';
                              echo '&lt;td&gt;'. $row['email'] . '&lt;/td&gt;';
                              echo '&lt;td&gt;'. "&lt;a class='btn btn-primary' href=edit.php?id=".$row["id"]."&gt;&amp;nbsp;&amp;nbsp;Edit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;&lt;br&gt;"."&lt;a class='btn btn-danger' href=delete.php?id=".$row["id"]."&gt;&amp;nbsp;&amp;nbsp;Delete&lt;/a&gt;&lt;br&gt;";
       }
  
  
  } 
      else {
      echo "0 results";
  }
  
  
  
  echo "&lt;/tbody&gt;";  
   echo "&lt;/table&gt;";
  
  
  $sql = "SELECT COUNT(*) FROM student_form"; 
  $retval1 = mysqli_query($link, $sql);  
  $row = mysqli_fetch_row($retval1);  
  $total_records = $row[0];
      //  echo $total_records;
  $total_pages = ceil($total_records / $limit);  
  //$pagLink = "&lt;div class='pagination'&gt;";  
  for ($i=1; $i&lt;=$total_pages; $i++) {  
  
      echo "&lt;ul class='pagination'&gt;";
  
      echo "&lt;li&gt;&lt;a href='index.php?page=".($page-1)."' class='button'&gt;Previous&lt;/a&gt;&lt;/li&gt;"; 
      echo "&lt;li&gt;&lt;a href='index.php?page=".$i."'&gt;".$i."&lt;/a&gt;&lt;/li&gt;";
      echo "&lt;li&gt;&lt;a href='index.php?page=".($page+1)."' class='button'&gt;NEXT&lt;/a&gt;&lt;/li&gt;";
  
  
      echo"&lt;/ul&gt;";               
  };  
  //echo $pagLink . "&lt;/div&gt;";     
      mysqli_close($link);
  ?&gt;
  
  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>