Nother Pagination Q

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Nother Pagination Q

Post by Steveo31 »

viewtopic.php?t=25692&highlight=

There's the battle that was finally won. The question I have now is about showing the page numbers. Some of the results will have 40 pages, and I'd like it to show the pages like the forums here,

Code: Select all

First 1, 2, 3... Last
I can't figure it out. I've thought about loops, but can't figure how to implement.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

psuedo code:

Code: Select all

if num_pages < 6
  loop out page links to all pages
else
  loop out page 1, 2, 3
  drop an ellipsis
  loop out current_page - 1 -> current_page + 1
  drop an ellipsis
  loop out page n - 2, n - 1, n (last_page)
  remove overlaps, favoring the previously set.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Ok, I've been at this for a while... no luck.. Here's the code I thought might work, but nope.

Code: Select all

$limit = $totalPages-($totalPages-$page);
                        if($limit > 10){
                            $limit = 10;
                        }else{
                            $limit = $totalPages-($totalPages-$page);
                        }
                        for($p=$page; $p<$limit; $p++){
                            if($p != $page){
                                echo "<a href='$url&page=$p'>".$p."</a>&nbsp;";
                            }else{
                                echo "<b style='color:#999'>".$p."</b>&nbsp;";
                            }
                        }
I can't put my train of thought into words... made sense about 10 min ago, but I can't think now... overkill. Hah.

If you could, give me another push :)
Post Reply