Web Hosting Talk







View Full Version : Limit pagination display characters with ...


lexington
08-11-2008, 04:48 PM
Hello, I have working pagination code but was curious to know that if there are 10 or more pages for example, instead of displaying every page numbers such as 1 2 3 4 5 6 7 8 9 10, could it display 1 2 3 ... 8 9 10 like how forums display a lot of page links. Here is my pagination code if you could edit it with a working example that would be great:

list($total) = mysql_fetch_row($result);
$total_pages = ceil($total / $page_limit);

$page = intval(@$_GET["page"]);

if ($page == 0)
{
$page = 1;
}

$start = $page_limit * ($page - 1);
$end = $page_limit * $page;

if ( $start <> 0 )
{
$new_prev = $page -1;
$prev = "<a href='".$page_path."page=$new_prev'>&laquo; Previous</a>&nbsp;";
}
if ( $end < $total )
{
$new_next = $page +1;
$next = "&nbsp;<a href='".$page_path."page=$new_next'>Next &raquo;</a>";
}

for ($i = 1; $i <= $total_pages; $i++)
{
$page_number = ( $total_pages > 1 ) ? $i : '';

if ($page != $i)
{
$page_number = "<a href='".$page_path."page=$i'>$page_number</a>";
}

$pagination .= '&nbsp;' . $page_number . '&nbsp;';
}

Thanks :)