Pagination with a PHP class

I’ve recently wrote a pagination class for php, I used to do this in a procedural way by using functions, it’s always worked fine, but its not as reusable as a class is.

I’ve released this class on Github this tutorial will explain how to use the pagination class.

  1. Include the class
  2. create a new instance of the class, set the number of records by page and a reference
  3. Then set the total number of records, do this by either setting in manually or by counting records from a dataset
  4. Set the total number of records by passing the total to the method set_total()
  5. Then display the records as normal
  6. To show the page links echo page_links() optionally passin 2 parameters the first set the address by default this is ? the second parameter is for any $_GET’s you want to pass from page to page.

Download the class from Github

 

  • http://www.biztechconsultancy.co.uk/php-web-development.htm PHP Web Development

    I faced problem while creating a new class. I do lots of things to solve it but haven’t succeed. what can i do now? any solution ?

    • http://www.daveismyname.com David Carr

      do you receive any errors?

      Also did you include the pagination class that this tutorial is based on?

      • http://www.biztechconsultancy.co.uk/php-web-development.htm PHP Web Development

        I received creating new class error while i make new class.. Yeah I include it..

  • Guest

    I received creating new class error while i make new class.. Yeah I include it.

    • http://www.daveismyname.com David Carr

      what was the error?

  • mrashutoshanand

    awesome tutorials..