PHP Classes


Recommend this page to a friend!
  Classes of Allan Kibet  >  Simple PDO Pagination class  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Read me
Class: Simple PDO Pagination class
Get results and links for queries split in pages
Author: By
Last change:
Date: 3 years ago
Size: 1,278 bytes


Class file image Download

Simple PDO Pagination Package

This is a simple PHP package that lets you paginate your select queries making it easier to navigate a list of records with simple navigation links.

Composer Installation

### Usage


use Pagination\Pager;

// Create your PDO connection object $pdo = new \PDO("mysql:host=localhost;port=3306;dbname=testdb", 'root', 'r00t');

// Initiate your pager $p = new Pager($pdo, "SELECT * FROM users");

// Set you page URL $p->setPageUrl("http://localhost/users");

// Set your per page limit $p->setPerPage(10);

$dataRecords = $p->paginate()->data;

foreach($dataRecords as $data) {

echo $data->id.' '.$data->first_name.' '.$data->last_name.'<br />';


if(isset($p->paginate()->firstLink)) {

echo "<a href='{$p->paginate()->firstLink}'> << </a> | ";


if(isset($p->paginate()->backLink)) {

echo "<a href='{$p->paginate()->backLink}'> < </a>";


echo "[{$p->paginate()->currentPage}]";

if(isset($p->paginate()->nextLink)) {

echo "<a href='{$p->paginate()->nextLink}'> > </a> | ";


if(isset($p->paginate()->lastLink)) {

echo "<a href='{$p->paginate()->lastLink}'> >> </a>";


for JSON

header('Content-Type: application/json'); echo $p->paginateJSON();

For more information send a message to info at phpclasses dot org.