I use the following script to make previous and next pages in a shopping cart getting results from a mysql db. But, some of the results return like 15 pages, and I need to find a way so that it will display only pages 1-10 links, and an arrow or something for 11-20, so that I don't have a huge row of numbers stretching across my page. I have not been able to figure out how to do this using the same type of structure below:
if ($offset >= 1) { // bypass PREV link if offset is 0
$prevoffset=$offset-$limit;
print "<a href=\"shop.php?CatSelect=$CatSelect&offset=$prevoffset&limit=$resultlimit\">PREV</a> \n";
}
$pages=intval($num/$limit);
if ($num%$limit) {
$pages++;}
for ($i = 1; $i <= $pages; $i++) {
$newoffset = $limit*($i-1);
if ($newoffset == $offset) {
print "$i \n";
} else {
print "<a href=\"shop.php?CatSelect=$CatSelect&offset=$newoffset&limit=$resultlimit\">$i</a> \n";
}}
if (! ( ($offset/$limit) == ($pages - 1) ) && ($pages != 1) ) {
$newoffset = $offset+$limit;
print "<a href=\"shop.php?CatSelect=$CatSelect&offset=$newoffset&limit=$resultlimit\">NEXT</a><p>\n";
}
(I modified this from on the articles here on phpbuilder. It basically displays as:
PREV 1 2 3 4 5 6 7 8 9 10 NEXT
But will display all page numbers in the middle even if there are 100.