PHP Classes

Simple PDO Pagination class: Get results and links for queries split in pages

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 165 This week: 1All time: 8,898 This week: 560Up
Version License PHP version Categories
simple-pdo-pager 1.0BSD License7PHP 5, Databases
Description 

Author

This class can get results and links for queries split in pages.

It can connect to a given database using PDO and execute a given SQL query.

The class can retrieve result record values for the given query limiting the range of result records to a given page that contains a limited number of records per page.

It can also return the URLs of pages to navigate to other pages of results given a base URL for the current page that displays the paginated listing.

Picture of Allan Kibet
Name: Allan Kibet <contact>
Classes: 4 packages by
Country: United Kingdom
Age: ???
All time rank: 2443112 in United Kingdom
Week rank: 109 Up5 in United Kingdom Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Documentation

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

<?php

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


  Files folder image Files  
File Role Description
Files folder image.idea (6 files)
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  .idea  
File Role Description
  Accessible without login Plain text file misc.xml Data Auxiliary data
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file simple-pdo-pager.iml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data
  Accessible without login Plain text file workspace.xml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imagePagination (1 file)

  Files folder image Files  /  src  /  Pagination  
File Role Description
  Plain text file Pager.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:165
This week:1
All time:8,898
This week:560Up
User Comments (1)