Simple PHP Pagination Class

This is a simple to use PHP pagination class object to make it easier for those not comfortable with paginating results to be able to do so with ease. Simply pass the regular query for all results, the page number, set the number of results per page and you've got a fully working PHP paginator. There are also lots of other features you can achieve including the pagination links can be customised with the templates

Usage

Class Homepage: http://www.jaygilford.com/php/completely-customisable-php-pagination-class/

To instantiate the class you will need two things
- The current page number (from $_GET['page'] for example)
- The query you need to run

So say we have
$query = "SELECT * FROM PRODUCTS";
$page = isset($_GET['page']) ? $_GET['page'] : 1;

we would then call the class with
$pag = new pagination($page, $query);

Once that has been done, all that is left is to call
$pag->paginate();

This will run the pagination, and store the MySQL result for your results loop.
To get the resource, simply use
$pag->resource();
for example, suppose your normal code was
while($row = mysql_fetch_assoc($result)) {
// Code here for each result
}
Simply change $result to $pag->resource() and it will get the results from the query

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

You can also change a number of settings for the class, such as putting
$pag->results_per_page = 5;
will change the number of results to 5 per page


PLEASE BE SURE TO CHANGE ALL SETTINGS BETWEEN CREATING THE CLASS AND THE $pag->paginate(); OR THE CHANGE WONT BE SEEN IN THE RESULTS

Finally, to show your pagination links output, simply use
echo $pag;
This will show the | >>| structure wherever you echo it. You can change the format of these using $pag->tpl_prev for example to change the previous page output link

If you have any questions regarding this feel free to contact me via email (contact details can be found at http://www.jaygilford.com/contact/)

Comments

Posted 8 hours ago by unknown user

nice script

Posted 27 days ago by unknown user

vijay: This pagination topic is very help to me



loader

progress bar