Pagination in Php SQLITE
<p>I'm quite new to PHP. I'm playing around with connecting to a <code>sqlite</code> database and I've done that successfully. For some reason my pagination is not working. </p>

<p>The value of <code>$page</code> won't go beyond 2. Can someone help me out, I'm sure its probably a simple mistake. (So currently it does change from the first page to the next. </p>

<p><img src="https://i.stack.imgur.com/dl4xe.png" alt="A screenshot of the database (as it is currently)"></p>

<pre><code>    &lt;?php
  try
  {
    //open the database
    $db = new PDO('sqlite:client.db');

    //create the database
    $db-&gt;exec("CREATE TABLE IF NOT EXISTS Client (id INTEGER PRIMARY KEY AUTOINCREMENT, first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(50), gender VARCHAR(50))");

$page = 1;
if(!empty($_GET['page'])) {
    $page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
    if(false === $page) {
        $page = 1;
    }
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    //something posted

    if (isset($_POST['Previous'])) {
        print 'current value of $page = ' . $page;
        print "&lt;br&gt;";
        if($page &lt;= 0) {
          $page = 1;
        }else {
          $page = $page - 1;
        }
    } else if(isset($_POST['Next'])) {
        print 'current value of $page = ' . $page;
        print "&lt;br&gt;";
        $page = $page + 1;
    }
}





// set the number of items to display per page
$limit = 10;

// build query
$offset = ($page - 1) * $limit;
if($offset &lt;= 0) {
  $offset = 0;
}
print '$page = ' . $page;
print "&lt;br&gt;";
print '$offset = ' . $offset;
    //now output the data to a simple html table...
    print "&lt;table border=1&gt;";
    print "&lt;tr&gt;&lt;td&gt;Id&lt;/td&gt;&lt;td&gt;First Name&lt;/td&gt;&lt;td&gt;Last Name&lt;/td&gt;&lt;td&gt;Age&lt;/td&gt;&lt;td&gt;Gender&lt;/td&gt;&lt;/tr&gt;";
    $sql = "SELECT * FROM Client LIMIT " . $offset . "," . $limit;

    $result = $db-&gt;query($sql);
    //$rows = count($result);
    //print $rows;
    //checks if table has data
    //$count = $result-&gt;fetchColumn();

    foreach($result as $row)
    {
      print "&lt;tr&gt;&lt;td&gt;".$row['id']."&lt;/td&gt;";
      print "&lt;td&gt;".$row['first_name']."&lt;/td&gt;";
      print "&lt;td&gt;".$row['last_name']."&lt;/td&gt;";
      print "&lt;td&gt;".$row['email']."&lt;/td&gt;";
      print "&lt;td&gt;".$row['gender']."&lt;/td&gt;&lt;/tr&gt;";
    }


  print "&lt;/table&gt;";
  print "&lt;br&gt;";
  //print "&lt;button type=\"button\" name=\"button\"&gt;&lt;&lt; Previous &lt;/button&gt;";
  //print "&lt;button type=\"button\" name=\"button\"&gt;Next &gt;&gt;&lt;/button&gt;";
  print "&lt;form class=\"\" action=\"\" method=\"post\"&gt;";
  print  "&lt;button type=\"submit\" name=\"Previous\"&gt;Previous&lt;/button&gt;";
  print  "&lt;br&gt;&lt;br&gt;&lt;button type=\"submit\" name=\"Next\"&gt;Next&lt;/button&gt;";
  print "&lt;/form&gt;";

    // close the database connection
    $db = NULL;
  }
  catch(PDOException $e)
  {
    print 'Exception : '.$e-&gt;getMessage();
  }
?&gt;
</code></pre>