title: Achieve pagination feature in Ajax/PHP/JQuery
body: <p>I'm trying to perform pagination feature. Until now, I manage to generate the feature according to the data number in my database. </p>
  
  <p>I'm using MariaDB. The problem is that when I try to click on page 2, the parameter is got back well in the url : xxx.php?page=2, but data are not updated !</p>
  
  <p>Page always displays the same data. No error is displayed in logs</p>
  
  <pre><code>&lt;?php
  require('config/config.php');
  
  if(isset($_SESSION['flash']))
  {
      foreach($_SESSION['flash'] as $type =&gt; $message)
      {
          echo $message;
      }
      unset($_SESSION['flash']);
  }
  
  $output = '';
  $limit_per_page = 5;
  $page = "";
  if(isset($_POST["query"]))
  {
      $query = $cnx-&gt;prepare("SELECT * FROM candidacies WHERE lastName LIKE :lastName OR firstName LIKE :firstName OR age LIKE :age OR scheduleRange LIKE :scheduleRange OR phoneNumber LIKE :phoneNumber OR email LIKE :email OR candidacyType LIKE :candidacyType");
      $element = "%".$_POST['query']."%";
      $query-&gt;bindValue(':lastName', $element, PDO::PARAM_STR);
      $query-&gt;bindValue(':firstName', $element, PDO::PARAM_STR);
      $query-&gt;bindValue(':age', $element, PDO::PARAM_INT);
      $query-&gt;bindValue(':scheduleRange', $element, PDO::PARAM_STR);
      $query-&gt;bindValue(':phoneNumber', $element, PDO::PARAM_STR);
      $query-&gt;bindValue(':email', $element, PDO::PARAM_STR);
      $query-&gt;bindValue(':candidacyType', $element, PDO::PARAM_STR);
  }
  else if(isset($_POST['entries']))
  {
      $entries = intval($_POST['entries']);
      $query = $cnx-&gt;prepare("SELECT * FROM candidacies LIMIT :entries");
      $query-&gt;bindValue(':entries', $entries, PDO::PARAM_INT);
  }
  else
  {       
      $page = (!empty($_GET['page']) ? $_GET['page'] : 1);
      $start = ($page - 1) * $limit_per_page;
  
      $query = $cnx-&gt;prepare("SELECT SQL_CALC_FOUND_ROWS * FROM candidacies LIMIT :limit_per_page OFFSET :start");
      $query-&gt;bindValue(':limit_per_page', $limit_per_page, PDO::PARAM_INT);
      $query-&gt;bindValue(':start', $start, PDO::PARAM_INT);
  }
  
  $query-&gt;execute();
  $result = $query-&gt;fetchAll(PDO::FETCH_ASSOC);
  $count = $query-&gt;rowCount();
  
  $resultFoundRows = $cnx-&gt;prepare('SELECT found_rows()');
  $resultFoundRows-&gt;execute();
  $listElements = $resultFoundRows-&gt;fetchColumn();
  
  if($count &gt; 0)
  {
      $output .= '
          &lt;table class="table table-striped" id="candidaciesTable"&gt;
          &lt;thead class="thead-light"&gt;
              &lt;tr&gt;
                  &lt;th scope="col"&gt;firstName&lt;/th&gt;
                  &lt;th scope="col"&gt;lastName&lt;/th&gt;
                  &lt;th scope="col"&gt;Âge&lt;/th&gt;
                  &lt;th scope="col"&gt;Schedule Range&lt;/th&gt;
                  &lt;th scope="col"&gt;Phone number&lt;/th&gt;
                  &lt;th scope="col"&gt;Email&lt;/th&gt;
                  &lt;th scope="col"&gt;Candidacy Type&lt;/th&gt;
                  &lt;th scope="col"&gt;Action&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
      ';
      foreach($result as $key =&gt; $value)
      {
  
          $output .= "
              &lt;tr&gt;
                  &lt;td&gt;".htmlspecialchars($value["firstName"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($value["lastName"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($value["age"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($value["scheduleRange"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($value["phoneNumber"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($value["email"])."&lt;/td&gt;
                  &lt;td&gt;".htmlspecialchars($search["candidacyType"])."&lt;/td&gt;
                  &lt;td&gt;
                      &lt;div class='btn-group'&gt;
                          &lt;button class='btn btn-light btnViewCandidacy' id=".$value['id']."&gt;
                              &lt;i class='far fa-eye'&gt;&lt;/i&gt;
                          &lt;/button&gt;
                          &lt;button class='btn btn-info' id='btnEditCandidacy' onclick='editCandidacy(".$value['id'].")'&gt;
                              &lt;i class='far fa-edit'&gt;&lt;/i&gt;
                          &lt;/button&gt;
                          &lt;button class='btn btn-danger' id='btnDeleteCandidacy' onclick='deleteCandidacy(".$value['id'].")'&gt;
                              &lt;i class='far fa-trash-alt'&gt;&lt;/i&gt;
                          &lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          ";
      }
      $output .= "
              &lt;/tbody&gt;
          &lt;/table&gt;";
  
      $output .= '
          &lt;div class="pagination-centered"&gt;
              &lt;ul&gt;'
          ?&gt;
          &lt;?php 
              $numberPages = ceil($listElements / $limit_per_page);
              if($page &gt; 1):
                  $output .= '&lt;a href="?page='. ($page - 1).'"&gt;Prev&lt;/a&gt; —';
              endif;
              for ($i = 1; $i &lt;= $numberPages; $i++):
                  $output .= '&lt;a href="?page='.$i.'"&gt;'.$i.'&lt;/a&gt;';
              endfor;
              if($page &lt; $numberPages):
                  $output .= '&lt;a href="?page='.($page + 1).'"&gt;Next&lt;/a&gt;';
              endif;
              $output .= '
              &lt;/ul&gt;
          &lt;/div&gt;';
      echo $output;
  }
  else
  {
   echo '&lt;div class="alert alert-info"&gt;No results found !&lt;/div&gt;';
  }
  ?&gt;
  
  &lt;script&gt;
   $(document).ready(function()
   {
       loadData();
  
       function loadData(query)
       {
           $.ajax({
               url:"search.php",
               method:"POST",
               data:{query:query},
               success:function(data)
               {
                   $('#result').html(data);
               }
          });
      }
   }
  &lt;/script&gt;
  </code></pre>