Right now my pagination would show up something like this
[1] [2] [3] [4] [5] [6] [7] [8] [9]
How would i make it show up like this
[1] [2] [3] [4] [5]... [9]
<?php
$per_page = 10;
$pages_query = mysql_query ("SELECT COUNT(`message_id`) FROM `messages`") or die(mysql_error());
$pages = ceil(mysql_result ($pages_query, 0) / $per_page);
$page = (isset ($_GET['page'])) ? (int) $_GET['page'] : 1;
$start = ($page - 1) * $per_page;
?>
Relevant if statement that echo out pagination
<?php
if ($pages >=1 && $page <= $pages) {
for ($x=1; $x<=$pages;$x++) {
echo "<a href=\"?page=" .$x."\">".$x."</a>";
}
}
?>
Try this :
<?php
$link = "";
// $page = $_GET['page'];
// $pages=20; // Hardcoded for testing purpose
$limit=5 ;
if ($pages >=1 && $page <= $pages)
{
$counter = 1;
$link = "";
if ($page > ($limit/2))
{ $link .= "<a href=\"?page=1\">1 </a> ... ";}
for ($x=$page; $x<=$pages;$x++)
{
if($counter < $limit)
$link .= "<a href=\"?page=" .$x."\">".$x." </a>";
$counter++;
}
if ($page < $pages - ($limit/2))
{ $link .= "... " . "<a href=\"?page=" .$pages."\">".$pages." </a>"; }
}
echo $link;
?>
OUTPUT :
//At page=1
1 2 3 4 ... 20
//At page=12
1 ... 12 13 14 15 ... 20
//At page=18
1 ... 18 19 20
<?php
if ($pages >=1 && $page <= $pages) {
$counter = 1;
$link = "";
for ($x=1; $x<=$pages;$x++) {
if($counter < 5)
$link .= "<a href=\"?page=" .$x."\">".$x."</a>";
$counter++;
}
$link .= "...";
$link .= "<a href=\"?page=" .$pages."\">".$pages."</a>";
}
echo $link;
?>