title: PHP and Ajax pagination. Why GET method always returns empty value?
body: <p>I'm trying to add pagination, even though the code it seems correct, the page displays only the first 10 results (10 results i want per page). As you can see below, the problem seems to be created in the <code>$_GET</code> method. <br><br>
  Here is the ajax: <br></p>
  
  <pre><code>   function displayAllTopics() {
          $.ajax({
            url: "requests.php",
            type: "GET",
            data: {
            keyPagination: "displayAllTopics"
            },
            dataType: "json",
            success: function(response) {
              $("#topicArea").append(response.response_message);
              $("#pagination").append(response.pagination);
            }
          });
        }
  </code></pre>
  
  <p>Here is the <code>requests.php</code> file:<br></p>
  
  <pre><code>  if(isset($_GET['keyPagination'])) {
   if($_GET['keyPagination'] == "displayAllTopics") {
     $sql =  "SELECT * FROM travel";
     $result = mysqli_query($conn, $sql);
     $count_topics = mysqli_num_rows($result);
     if($count_topics &lt; 1) {
       exit('There are no topics yet.');
     }
  
     if(isset($_GET['page'])) {
       $page = $_GET['page'];
     }
     else {
       $page = 1;
     }
  
      //results per page
      $results_per_page = 10;
      //number of pages
      $offset = ($page-1) * $results_per_page;
      $number_of_pages = ceil($count_topics / $results_per_page);
  
       $sql_pagination = "SELECT * FROM travel LIMIT $offset, $results_per_page";
       $results_pagination = mysqli_query($conn, $sql_pagination);
       $response_message = "";
       $pagination = "";
     while($row = mysqli_fetch_assoc($results_pagination)) {
       $user_id = $row['user_id'];
       $travel_subject_id = $row['travel_subject_id'];
       $travel_subject_date = $row['travel_subject_date'];
       $travel_title = $row['travel_subject_title'];
       $travel_body = $row['travel_subject_body'];
       $travel_comments_count = $row['travel_comments_count'];
       $travel_views = $row['travel_subject_views'];
       $travel_subject_date_format = date('j M y H:i', strtotime($travel_subject_date));
       $sql_user = "SELECT * FROM forum_users WHERE user_id='$user_id'";
     $result_user = mysqli_query($conn, $sql_user);
     if($row_user = mysqli_fetch_assoc($result_user)) {
       $username = $row_user['username'];
     $response_message .= "&lt;tr&gt;
       &lt;td&gt;&lt;a href='travel_subject.php?id=".$travel_subject_id."' onclick='countview(".$travel_subject_id.");'&gt;&lt;img src='topic.png' class='img_first'&gt;$travel_title&lt;/a&gt;&lt;/td&gt;
       &lt;td&gt;&lt;img src='comment.png' class='img_second'&gt;&lt;p&gt;$travel_comments_count&lt;/p&gt;&lt;/td&gt;
       &lt;td&gt;&lt;a href='profile_user.php?id=".$user_id."'&gt;&lt;img src='avatar.png' class='img_third'&gt;$username&lt;/a&gt;&lt;/td&gt;
       &lt;td&gt;&lt;p&gt;&lt;img src='views.png' class='img_four'&gt;$travel_views&lt;/p&gt;&lt;/td&gt;
       &lt;td&gt;&lt;p&gt;$travel_subject_date_format&lt;/p&gt;&lt;/td&gt;
       &lt;/tr&gt;";
     }
   }
   for ($i = 1; $i &lt;= $number_of_pages; $i++) {
    $pagination .= "&lt;a href='forum_index.php?page=".$i."&amp;limit=".$offset."'&gt;$i&lt;/a&gt;";
   }
  
   $data = array('response_message' =&gt; $response_message, 'pagination' =&gt; $pagination);
   echo json_encode($data);
  
   exit();
   }
   }
  </code></pre>
  
  <p><strong>Note</strong>: Variable <code>$page</code> is always 1, so it seems that cannot set the <code>$_GET['page']</code> and as a result from that, the page below displays always the first 10 results. Why is that?<br><br>
  and here is the php file, that i want to display the results: <br><br></p>
  
  <pre><code> &lt;div class='display-subjects'&gt;
    &lt;table class='display-subjects-table' cols='5'&gt;
  &lt;tbody id="topicArea"&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;div id='pagination'&gt;
    &lt;?php
    if(isset($_GET['page'])) {
      $page = $_GET['page'];
    }
    else {
      $page = 1;
    }
  ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Where is the wrong part? Thanks in advance.</p>