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.

7 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)

Leave a comment

what will you say?


Recently Elsewhere

Recent Entries

  • Say "Hello" to Daisy Amelia Hailey Reese

    In a way I am never to forget, our newest addition, Daisy Amelia Hailey Reese, was brought into the world at 5:16am on June...

  • Meet Melody

    People who know me, know that I love [Movable Type](http://www.majordojo.com/cgi-bin/mt/mt-search.cgi?blog_id=3&tag=movable%20type&limit=20). In fact I have devoted much of the last five years to the product and...

  • MOONSHOT

    On a recent trip to Chicago I stopped by a non-local mega-bookstore to look for a last minute gift for Harper as is required on...

  • Understanding Movable Type Template Sets

    Since releasing the [Hybrid News Theme](http://www.majordojo.com/2009/05/teaser-hybrid-news-theme-for-movable-type.php) I have been contacted by a number of people on the [ProNet mailing list](http://www.sixapart.com/mailman/listinfo/pronet/) asking me to shed some...

  • Obama's Speech to the Muslim World

    I implore everyone to watch Obama's speech. His entire speech is profound. It is moving in how it acknowledges and embraces our past, but...

badge-iheartmelody-white.png