Adding 'prev' and 'next' buttons to PHP pagination. And taking out loads of numbers in the middle
<p>I am dealing with a site that displays information about holidays from a MySQL database. I have successfully managed to display the information in a list format and include pagination with about 20 entries per page, but because there are quite a lot of entries, I just end up with loads of numbers at the bottom which doesn't look pretty. I was wondering if anyone knows how to include 'prev' and 'next' buttons on either side in PHP and also take some of the numbers out of the middle and replace them with '...', just like the pagination format that this site uses if you look at the bottom of the questions pages.</p>

<p>Here's my code:</p>

<pre><code>&lt;?php

//connect
mysql_connect('localhost', 'xxxx', 'xxxx') or die(mysql_error()); 
mysql_select_db('hdb') or die(mysql_error());

//pagination
$per_page = 20;

$pages_query = mysql_query("SELECT COUNT('id') FROM `holidaytable` WHERE brandname = 'Spain'");
$count = mysql_result($pages_query, 0);
$pages = ceil(mysql_result($pages_query, 0) / $per_page);

$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;

echo '&lt;p&gt;There are '.$count.' holidays&lt;hr&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;';

//construct query and insert values

$query = mysql_query("SELECT * FROM holidaytable WHERE brandname = 'Spain' LIMIT $start, $per_page") or die(mysql_error());

while($rows = mysql_fetch_assoc($query))
{
   $name = $rows['name'];
   $id2 = $rows['id2'];
   $hotelname = $rows['hotelname'];
   $desc = $rows['desc'];
   $spec = $rows['spec'];
   $resort = $rows['resort'];
   $awtrack = $rows['awtrack'];
   $awthumb = $rows['awthumb'];
   $awimage = $rows['awimage'];
   $mthumb = $rows['mThumb'];
   $mlink = $rows['mlink'];
   $mimage = $rows['mimage'];
   $awcatid = $rows['awcatid'];
   $mcat = $rows['mcat'];
   $brandname = $rows['brandname'];

   echo "$id2 &lt;br&gt;$name &lt;br&gt;$hotelname &lt;br&gt;$desc &lt;br&gt;&lt;h2&gt;$resort, $brandname&lt;/h2&gt;&lt;br&gt;&lt;img src='$mthumb'&gt;&lt;br&gt;&lt;img src='$mimage'&gt; &lt;br&gt; &lt;a href='$awtrack' target='_blank'&gt;link&lt;/a&gt;";
   echo "&lt;br /&gt;&lt;br /&gt;&lt;hr&gt;";
};
//pagination

if ($pages &gt;= 1 &amp;&amp; $page &lt;= $pages) {
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; ';
}
}
mysql_close();
?&gt;
</code></pre>
