title: Pagination with PDO and MySQL
body: <p>Im trying to return all records from my database and paginate them accordingly, </p>
  
  <p>I have the following I've managed to wrangle together from a tutorial only It doesnt seem to output anything to my browser so I presume I've made an error in my syntax? </p>
  
  <pre><code>// No County Selected
          try
          {
          $per_page = '3';
          $res = $conn-&gt;prepare("SELECT * FROM directory WHERE user_active != ''");
          $rows = $res -&gt;fetchAll();
          $total_records = count($rows);
          $pages = ceil($total_records / $per_page); 
          $page  = (isset ($_GET['page']))  ? (int) $_GET['page'] : 1 ;
          $start = ($page - 1) *  $per_page; 
          $query = $db-&gt;query("SELECT * FROM directory LIMIT $start , $per_page");
          while($row = $query-&gt;fetch(PDO::FETCH_ASSOC)){
          echo '&lt;br&gt;' . $row['id'];
          } ?&gt;
          &lt;br&gt;&lt;br&gt;
          &lt;?php
          if ($pages &gt;=  1 &amp;&amp; $page &lt;= $pages){
          //if ($page&gt;1 &amp;&amp; $page &lt;= $pages){$previous=($page -1); echo '&lt;a href="?page=' .$previous. '"&gt;Previous&lt;/a&gt;';}
          for($x=1; $x&lt;=$pages; $x++){ echo ($x == $page) ? ' &lt;strong&gt;&lt;a href="?page='.$x.'"&gt;'.$x.'&lt;/a&gt;&lt;/strong&gt; ' : ' &lt;a href="?page='.$x.'"&gt;'.$x.'&lt;/a&gt; ';}
          //if ($page&gt;1  &amp;&amp; $page &lt;= $pages){ $next=($page+1) ; echo '&lt;a href="?page=' .$next. '"&gt;Next&lt;/a&gt;';}
          }
  </code></pre>