title: Pagination with Page numbers?
body: <p>I have a page which get's populated dynamically from a Mysql database.</p>
  
  <p>To prevent to much information been displayed at once, I have added pagination to page.</p>
  
  <p>Using this code.</p>
  
  <p>
  
  <pre><code>$currentPage = $_SERVER["PHP_SELF"];
  $maxRows_atoz = 10; $page= 0;
  if (isset($_GET['page'])) {$page= $_GET['page'];}
  $startRow_atoz = $page* $maxRows_atoz;
  
  mysql_select_db($database_main, $main);
  $query_atoz = "SELECT * FROM main WHERE title LIKE 'A%'"; 
  $query_limit_atoz = sprintf("%s LIMIT %d, %d", $query_atoz, $startRow_atoz, $maxRows_atoz);
  $atoz = mysql_query($query_limit_atoz, $main) or die(mysql_error());
  $row_atoz = mysql_fetch_assoc($atoz);
  
  if (isset($_GET['totalRows_atoz'])) {$totalRows_atoz = $_GET['totalRows_atoz'];} else {$all_atoz = mysql_query($query_atoz); $totalRows_atoz = mysql_num_rows($all_atoz);}
  $totalPages_atoz = ceil($totalRows_atoz/$maxRows_atoz)-1;
  $queryString_atoz = ""; if (!empty($_SERVER['QUERY_STRING'])) {$params = explode("&amp;", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) {
  if (stristr($param, "pageNum_atoz") == false &amp;&amp; stristr($param, "totalRows_atoz") == false) {array_push($newParams, $param);}}
  if (count($newParams) != 0) {$queryString_atoz = "&amp;" . htmlentities(implode("&amp;", $newParams));}}    
  $queryString_atoz = sprintf("&amp;totalRows_atoz=%d%s", $totalRows_atoz, $queryString_atoz);
  
  ?&gt;
  
  &lt;ul&gt;
  &lt;li class="previous"&gt; &lt;?php if ($page &gt; 0) { // Show if not first page ?&gt;
  &lt;a title="See Previous 10 Results" href="&lt;?php printf("?page=%d%s", $currentPage, max(0, $page - 1), $queryString_atoz); ?&gt;"&gt;
  &lt;img src="/files/previous.png" /&gt;&lt;/a&gt;
  &lt;?php } // Show if not first page ?&gt;&lt;/li&gt;
  &lt;li class="next"&gt;  &lt;?php if ($page &lt; $totalPages_atoz) { // Show if not last page ?&gt;
  &lt;a title="See Previous 10 Results" href="&lt;?php printf("?page=%d%s", $currentPage, min($totalPages_atoz, $page + 1), $queryString_atoz); ?&gt;"&gt;
  &lt;img src="/files/next.png" /&gt;&lt;/a&gt;
  &lt;?php } // Show if not last page ?&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>The code works in paginaing the results, but has a limitation.
  It currently only display's Next and Previous buttons. </p>
  
  <p>I would like to add page numbers. This way a user can skip to 4th or 5th page in the result set rather than having to press the next button 4 or 5 times.</p>
  
  <p>So, can some please tell me how I would go about doing this?</p>
  
  <p>Thanks</p>