View Single Post
Old 10-21-2003, 02:44 PM   #1 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Paginating & range()

I'm working on a script that uses pagination to limit the amount of rows returned, and display links forward and back to navigate through different result pages. Script works fine, but I've got over 13,000 rows in one DB, so it spits out several hundred pages.

I've been trying to find the secret to showing a range of pages vs showing all pages, (like vbulletin uses for search results) and have something like this:
PHP Code:

$range 
range(($page-3), ($page+3));
foreach (
$range as $value) {
    if (
$value == $page) {
        echo 
"[$value] \n";
    } else {
        echo 
"<a href=\"{$_SERVER['PHP_SELF']}?page=$value\">$value</a>&nbsp;\n";
    }

Now, this works dandy, except if you are on page 1 ~ 5, it shows a negative value, eg:
-2 -1 0 1 2 3 4

Or when you are at or near the last page (say the last page is number 250):
247 248 249 250 251 252 253
even though the limit is 250, it still adds 3 to it.

I need to have a conditional like this:
If page_no is 1 ~ 5, don't subtract 3
If page_no is ($lastpage-3) ~ $lastpage, don't add 3
If page is between 5 ~ ($lastpage-3), subtract 3 and add 3 for the page range.

I can figure out the general outline, and I've tested the exact conditional I've shown, but it doesnt work. Any ideas are welcome.
bdl is offline   Reply With Quote