PHP Pagination Class Updated – Version 2

Based on feedback (and the long time between updates), I’m releasing an updated version of the PHP pagination class.

Changes

  • No more SQL errors if using the class on a query with no results (although I fail to see the point of using it on an empty query anyway, but the bug is fixed)
  • When selecting ‘ALL’ only one page is displayed, and if you are using the display_items_per_page drop-down menu, ‘ALL’ is now selected as well.
  • If a page less than page one, or greater than the total number of pages is requested, no results are displayed and the appropriate prevous/next links are disabled
  • The items per page array that populates the display_items_per_page drop-down menu is now an option that can be configured when instantiating the class. Previously this was hard-coded to the class.
  • The $high option has been removed from the class (it was never used).

Note that if you receive a PHP notice about undefined indexes that you should turn down your error reporting. This notice may be displayed when loading the page for the first time when no $_GET variables are present. The class accounts for this, however PHP throws a notice about it.

Examples

I’ve also added license info at the head of the class (CC Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)).

Download

70 thoughts on “PHP Pagination Class Updated – Version 2”

  1. i faced the Pagination problems like
    1. Not included First, Next, Previous, Last links
    2. When included the searching the search parameter goes to in url
    3. Sorting is not for each column
    if you have a time please explain how to solve it?

  2. Pagination class is fine. But following is included or i face following problems.

    1. Not included First, Next, Previous, Last links
    2. When included the searching the search parameter goes to in url, but for security it is very danger.
    3. Sorting for each column

  3. Hi, i have inserted your function to my website, but it show erros when installed on IIS server using PHP 5.14, Perhaps, your php function is not compatible with PHP-IIS

    any suggesstion? thank you.

  4. Tried example-form.php but when I use continent from drop-down menu, nothing displayed and drop-down menu text returns to : Please select a continent

  5. Hi Admin,

    There is lot of error
    Notice: Undefined variable: option in C:\xampp\htdocs\sattvic\page\paginator.class.2.php on line 119

    Notice: Use of undefined constant ipp – assumed ‘ipp’ in C:\xampp\htdocs\sattvic\page\paginator.class.2.php on line 111

    Notice: Undefined property: Paginator::$high in C:\xampp\htdocs\sattvic\page\example.php on line 115

    Could you please help me on this?

    1. I have an entirely new version in the works, but in the mean time you can turn your error reporting down — those are just notices.

  6. Hello:
    I love this script, but the problem that I am having is that it is using OLD connection methods. Seriously, something so brilliant and no mysqli or PDO. I will be back in the near future when I get to pagination in hopes that it is modernized for either mysqli or PDO, perhaps independent of which the programmer uses. BRILLIANT!!!

      1. Yes, exactly !!! This is by far the most popular pagination anywhere on the web and there is good reason for it. This really is brilliant. Like I said, I will revisit your site and begin working on getting it to mysqli in the near future but that is my problem. You rock with this!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>