title: Pagination MySQL PHP
body: <p>I'm trying to use pagination for a customer table using PHP, MySQL &amp; Bootstrap. I wrote this code: </p>
  
  <pre><code>&lt;div class="container mx-auto"&gt;
  &lt;!--Add class table-responsive for responsive table --&gt;
  &lt;table class="table mx-auto"&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Surname&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Phone&lt;/th&gt;
          &lt;th&gt;Address&lt;/th&gt;
          &lt;th&gt;Zipcode&lt;/th&gt;
          &lt;th&gt;City&lt;/th&gt;
          &lt;th&gt;Company&lt;/th&gt;
  
  
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;ul class="pagination"&gt;
          &lt;?php
          if(isset($_GET['page'])){
  
              $previous = $_GET['page'] - 1;
              if($previous = -1 ){
                  $previous = 0;
              }
              if($previous = 0){
                  echo '&lt;li class="page-item"&gt;&lt;a class="page-link" href="#"&gt;Previous&lt;/a&gt;&lt;/li&gt;';
              }
              else{
                  echo '&lt;li class="page-item"&gt;&lt;a class="page-link" href="?page='. $previous.'"&gt;Previous&lt;/a&gt;&lt;/li&gt;';
              }
          }
          $page_max = 10;
          $entriesInDatabase = $database-&gt;getData("SELECT count(id) FROM customers");
          $numberOfPages = ceil($entriesInDatabase['count(id)']/$page_max);
  
          for($i = 0; $i &lt; $numberOfPages; $i++){
  
              echo '&lt;li class="page-item"&gt;&lt;a class="page-link" href="?page='. $i . '"&gt;'. $i. '&lt;/a&gt;&lt;/li&gt;';
          }
          if(isset($_GET['page'])) {
              $page = $_GET['page'];
              $start = $page * 10;
              $end = ($page + 1) * 10;
              var_dump($start); 
              var_dump($end);
          }
          else{
              $page = 0;
              $start = $page * 10;
              $end = 10;
          }
  
          $customers = $database-&gt;getUsers("SELECT * FROM customers LIMIT $start, $end");
  
          ?&gt;
          &lt;li class="page-item"&gt;&lt;a class="page-link" href="#"&gt;Next&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
      &lt;?php
  
  
  
      foreach($customers as $customer){
          $name = $customer ['name'];
          $surname = $customer['surname'];
          $email = $customer['email'];
          $phone = $customer['phone'];
          $address = $customer['address'];
          $zipcode = $customer['zipcode'];
          $city = $customer['city'];
          $company = $customer['company'];
          $id = $customer['id'];
          echo "&lt;tr&gt;
                  &lt;td&gt;$name&lt;/td&gt;
                  &lt;td&gt;$surname&lt;/td&gt;
                  &lt;td&gt;$email&lt;/td&gt;
                  &lt;td&gt;$phone&lt;/td&gt;
                  &lt;td&gt;$address&lt;/td&gt;
                  &lt;td&gt;$zipcode&lt;/td&gt;
                  &lt;td&gt;$city&lt;/td&gt;
                  &lt;td&gt;$company&lt;/td&gt;
  
  
  
                &lt;/tr&gt;";
      }
      ?&gt;
  </code></pre>
  
  <p>I want each page to show 10 records from the database so giving a limit to my SQL query. What happends now is the following; page 0 shows 10 records, page 1 shows 20 records, page 2 shows also 20 records but page 9 shows 11 records. </p>
  
  <p>Could anyone help me out fixing this issue? </p>