hmmm, it depends. I'd like to ask a few questions before I suggest anything:
First, let's say you're on page 3. When you press 'Next 5', should it take you exactly five pages forwards to page 8 (3 + 5 = 8), or should it just take you to the first page in the next grouping of five (which would be 6, because you're in pages 6 - 10)?
I'm assuming the current group of five should always be centred around the page you're on, right? What i mean is, if you're on page 21, it would look like this:
19 20 21 22 23
and if you click on page 23, it would look like this:
21 22 23 24 25
I think that'd be the most sensible behaviour. If that's the case, try out this snippet (I've left out style formatting and stuff):
$numofpages = $totalrows / $limit;
// $prevGroup takes you back five (or however many) pages
$prevGroup = $page - 5;
if ($prevGroup < 1) {
$prevGroup = 1;
}
// $howManyLeft calculates the exact number of pages left to see, if less than 5
$howManyLeft = $page - 3;
if ($howManyLeft < 0) {
$howManyLeft = 0;
} else if ($howManyLeft > 5) {
$howManyLeft = 5;
}
if ($howManyLeft) {
echo "<a href=\"$PHP_SELF?page=$prevGroup&phrase=$phrase&sortList=$sortBy\">Prev " . $howManyLeft . '</a>';
}
// this is a little complicated; we need to know where to start the iterator, because if we just said
// foreach ($i = $page - 2...
// we might be starting from a negative number.
$startOfGroup = $page - 2;
if ($startOfGroup < 1) {
$startOfGroup = 1;
}
// we also have to check so we don't go off the end either
$endOfGroup = $startOfGroup + 4;
if ($endOfGroup > $numofpages) {
$endOfGroup = $numofpages;
}
// finally, now we iterate.
foreach ($i = $startOfGroup; $i =< $endOfGroup; $i ++) {
if ($i == $page) {
echo $i;
} else {
echo "<a href=\"$PHP_SELF?page=$i&phrase=$phrase&sortList=$sortBy\">$i</a>";
}
}
// now we have to make the same check we did at the beginning -- how many pages should be specified in 'Next x'
// $nextGroup takes you forward five (or however many) pages
$nextGroup = $page + 5;
if ($nextGroup > $numofpages) {
$nextGroup = $numofpages;
}
// $howManyLeft calculates the exact number of pages left to see, if less than 5
$howManyLeft = $numofpages - ($page + 2);
if ($howManyLeft < 0) {
$howManyLeft = 0;
} else if ($howManyLeft > 5) {
$howManyLeft = 5;
}
if ($howManyLeft) {
echo "<a href=\"$PHP_SELF?page=$nextGroup&phrase=$phrase&sortList=$sortBy\">Next " . $howManyLeft . '</a>';
}
Haven't tested this out, but it should work. Sorry, there's a bit of magic in there in spots; if you have any questions, don't hesitate to ask them.