I will never implement a pagination control again. Period.

Do you know how many times I have been working on an application that has to allow users to paginate through a list of something? 1,259,041.

Give or take a few of course.

Well, I finally had enough. There should be a simple open source control that can do this intelligently. Oh, but wait... there isn't. Until now.

I just finished a PHP Pagination Control that can output the usual "Next" and "Previous" page links, as well as a sequence of page numbers (depending upon how many pages are in the result set of course). I modelled the interaction after Flickr which has a very nice mechanism for jumping to the front and end of the list as well as navigating to nearby pages.

paginator.png

I have also made available a wide array of sample outputs from the control if the screenshot doesn't give you a good enough sense for what this thing looks like.

Feel free to download the latest version at any time. It is licensed under the BSD license giving more people all the flexibility they need for re-use and re-distribution.

8 Comments

Looks good - I can vision a new TestRun now :)

Thanks for the pagination control, tried it out tonight and it looks good, although there are a few bugs to iron out (go to page 2 then try and use the 'Prev' button to go back to page 1 :). Nearly there though!

Very neat! Now all we need is this to be an option within Movable Type templates. A resource-light MTPaginate perhaps :-)

I tried your Paginator class off and it didn't work quite right. I had to modify the paginate static method to look like this to work:

public static function paginate( $offset, $total, $limit, $base ) { //$offset = $options['offset']; //$base = $options['base_url']; //$total = $options['total']; //$limit = $options['limit'];

And then the Next function did not work correctly. I am using Apache 2.2 and PHP 5 if that helps.

not working for me!

php 4.4.1 mysql 3.23.49 apache 1.3.27

Parse error: syntax error, unexpected TSTRING, expecting TOLDFUNCTION or TFUNCTION or T_VAR or '}' in \libs\Paginator.php on line 3

change the lines: remove the bug change the lines:

37) print " ".($lastp-1)."\n"; 38) print " ".$lastp."\n";

into

37) print " ".($lastp-1)."\n"; 38) print " ".$lastp."\n";

bug found: change part of the lines 37 and 38 into 37 .$base.((($lastp - 2)* $limit)+1) 38 .$base.((($lastp-1)*$limit)+1)

Well, I might as well admit it: I am a noob.

I have built my own "CMS" system, but I can not figure out how to use your class :o

Please explaine how I can use this class on my pages.

Leave a comment

what will you say?


Recent Comments

Close