PHP Classes

PHP Pagination Links: Display links to browse pages of entry listings

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 196 This week: 1All time: 8,513 This week: 560Up
Version License PHP version Categories
pagination-links 1.0.1MIT/X Consortium ...5HTML, Databases
Description 

Author

This class can display links to browse pages of entry listings.

It can take as parameter the total number of entries in a listing, the limit number of entries to display per page and the number of the current listing page.

The class can generate links to browse to the other pages of the listings.

The format of the link URLs, show the first and last links, show links a page numbers are configurable options.

Picture of Miraz Mac
  Performance   Level  
Name: Miraz Mac <contact>
Classes: 13 packages by
Country: Bangladesh Bangladesh
Age: 29
All time rank: 201629 in Bangladesh Bangladesh
Week rank: 52 Up1 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

/**
 * Sample Use of PaginationLinks with PDO and SQLite
 * Works with other databases like MySQL, MSSQL etc. too!
 *
 * @package PaginantionLinks
 */

require_once '../src/Pagination.php';

use
MirazMac\Pagination\Pagination;

// Database file path
$db_file = __DIR__ .'/demoDataBase.sqlite';

// Connect to database using PDO
$db = new PDO('sqlite:'.$db_file);

// Current page number
$current_page = (int)@$_GET['page'];

// Number of items/rows per page
$items_per_page = 10;

// Fetch Number of total items from database
$sql = "SELECT COUNT(id) AS total_count FROM demoTable";
$query = $db->prepare($sql);
$query->execute();

$total_items = $query->fetch()['total_count'];

// Create pagination instance
$pagination = new Pagination($total_items, $current_page);
$pages = $pagination->parse();

// Get offset number
$start = $pagination->offset();
// Query the database to fetch paginated rows
$sql = "SELECT * FROM `demoTable` LIMIT $start, $items_per_page";
$query = $db->prepare($sql);
$query->execute();

while (
$row = $query->fetch()) {
    echo
'<pre>';
    echo
$row['id'].'.';
    echo
$row['name'];
    echo
'</pre>';
}

echo
'<hr/>';

echo
$pagination->renderHtml();


Details

Pagination

Generate PHP pagination links with ease.


  Files folder image Files  
File Role Description
Files folder imageexamples (1 file)
Files folder imagesrc (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file PDOExample.php Example Example script

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

 Version Control Unique User Downloads Download Rankings  
 83%
Total:196
This week:1
All time:8,513
This week:560Up