title: How to get next ID on next page PHP
body: <p>I want to read the different ID on different page, by using the prev/next button. </p>
  
  <p>If I click next button, I want to get the next ID, if I click previous button, it will back to the previous ID. Following is what I want.</p>
  
  <p>Example:</p>
  
  <ol>
  <li>testnext_pre1.php?<strong>id=1</strong>&amp;page=1 </li>
  <li>testnext_pre1.php?<strong>id=2</strong>&amp;page=2</li>
  <li>testnext_pre1.php?<strong>id=5</strong>&amp;page=3</li>
  </ol>
  
  <p>Here is my problem. As you can see, I get the same ID on every page because of my code. How to get the correct ID for the page? </p>
  
  <p><a href="https://i.stack.imgur.com/2GO4g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2GO4g.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/dUubJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dUubJ.jpg" alt="enter image description here"></a>
  Please take note: the IDs are not increase by sequence, as some contents might be deleted. So I don't want the answer something like "+1".</p>
  
  <pre><code>$rowsPerPage = 1;
  
  if(isset($_GET['page']))
  {
      $pageNum= $_GET['page'];
  }
  else
  {
      $pageNum = 1;
  }
  
  // preceding rows
  $previousRows =($pageNum - 1) * $rowsPerPage;
  
  $query = "SELECT * FROM news LIMIT $previousRows, $rowsPerPage";
  $result = mysql_query($query) or die('Error couldn\'t get the data').mysql_error();
  
      echo "&lt;table border=1&gt;\n";
      echo "&lt;tr&gt;&lt;th&gt;ID&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Password&lt;/th&gt;&lt;th&gt;Perm&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;
      &lt;th&gt;Date&lt;/th&gt;&lt;/tr&gt;";
      // print the results
      while(list($id,$name,$pass,$perm,$email,$date) = mysql_fetch_array($result))
      {
          echo "&lt;tr&gt;&lt;td&gt;$id&lt;/td&gt;&lt;td&gt;$name&lt;/td&gt;&lt;td&gt;$pass&lt;/td&gt;&lt;td&gt;$perm&lt;/td&gt;&lt;td&gt;$email&lt;/td&gt;
          &lt;td&gt;$date&lt;/td&gt;&lt;/tr&gt;";
      }
      echo '&lt;/table&gt;';
  
  
  $query = "SELECT COUNT(id) AS numrows FROM news";
  $result = mysql_query($query) or die('Error, couldn\'t get count title=\"$page\"').mysql_error();
  
  $row = mysql_fetch_assoc($result);
  $numrows = $row['numrows'];
  
  $lastPage = ceil($numrows/$rowsPerPage);
  $phpself = $_SERVER['PHP_SELF'];
  
  
  if ($pageNum &gt; 1)
  {
      $page = $pageNum - 1;
      $prev = "&lt;div class=\"paginationbtn floatleft\"&gt;&lt;a href=\"$phpself?id=$rowid&amp;amp;page=$page\"&gt;previous&lt;/a&gt;&lt;/div&gt;";
      $first = " &lt;a href=\"$phpself?page=1\" title=\"Page 1\"&gt;[First Page]&lt;/a&gt; ";
  }
  else
  {
      $prev = ' previous ';
      $first = ' [First Page] ';
  }
  
  if ($pageNum &lt; $lastPage)
  {
      $page = $pageNum + 1;
  
      $resultid = mysql_query("SELECT id FROM news");
      while($loopid=mysql_fetch_array($resultid))
      { 
          $rowid = $loopid['id'];
          $next = "  &lt;div class=\"paginationbtn floatright\"&gt;&lt;a href=\"$phpself?id=$rowid&amp;amp;page=$page\" title=\"Page $page\"&gt;next&lt;/a&gt;&lt;/div&gt; ";
      }
  }
  
  else
  {
      $next = ' [Next] ';
  }
  
  echo $prev . " " . $next;
  </code></pre>