2017 © Pedro Peláez
 

library resultsetpaginator

Simple pagination module where it accepts a database connection to provide pagination support. Also supports plain pagination.

image

tharangakothalawala/resultsetpaginator

Simple pagination module where it accepts a database connection to provide pagination support. Also supports plain pagination.

  • Sunday, July 15, 2018
  • by tharanga
  • Repository
  • 1 Watchers
  • 0 Stars
  • 803 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 18 % Grown

The README.md

ResultSet Paginator

This is a simple set of classes that provides you pagination data for a given query. This executes a query using a given database connection (PDO, mysqli). Also supports plain pagination., (*1)

Build Status Total Downloads Latest Stable Version License, (*2)

Usage Examples

Pagination with known result total count

use TSK\ResultSetPaginator\Paginator\PaginationProvider;

$page = empty($_GET['page']) ? 3 : $_GET['page'];
$limit = empty($_GET['limit']) ? 10 : $_GET['limit'];
$totalResultCount = $laravelModel->count(); // "SELECT COUNT(*) FROM table" for example

$paginationProvider = new PaginationProvider($page, $limit, $totalResultCount);
$paginationProvider->setVisiblePaginationRange(1);

$modelItems => $laravelModel
    ->offset($paginationProvider->offset())
    ->limit($limit)
    ->get();

$pagination = '';
foreach($paginationProvider->pages() as $page) {
    if ($page->isCurrentPage()) {
        $pagination .= " {$page->getDisplayValue()} ";
        continue;
    }

    $pagination .= " <a href='?page={$page->getPageNumber()}&limit={$limit}'>{$page->getDisplayValue()}</a> ";
}

echo $pagination;
The above example will produce the below output:

<< < 2 ~~3~~ 4 > >>, (*3)

Example usage with a PDO connection (ex: Laravel)

use TSK\ResultSetPaginator\QueryExecerFactory;

$page = empty($_GET['page']) ? 2 : $_GET['page'];
$limit = empty($_GET['limit']) ? 10 : $_GET['limit'];

$queryExecerFactory = new QueryExecerFactory(DB::connection()->getPdo(), $page, $limit);
$queryExecer = $queryExecerFactory->getQueryExecer();

/** @var \PDOStatement $stmt */
$stmt = $queryExecer->query($sql);
$records = $stmt->fetchAll();

$pagination = '';
foreach($queryExecer->paginationProvider()->pages() as $page) {
    if ($page->isCurrentPage()) {
        $pagination .= " {$page->getDisplayValue()} ";
        continue;
    }

    $pagination .= " <a href='?page={$page->getPageNumber()}&limit={$limit}'>{$page->getDisplayValue()}</a> ";
}

echo $pagination;
The above example will produce the below output:

<< < 1 ~~2~~ 3 4 5 > >>, (*4)

Example usage with a mysqli connection

use TSK\ResultSetPaginator\QueryExecerFactory;

$page = empty($_GET['page']) ? 2 : $_GET['page'];
$limit = empty($_GET['limit']) ? 10 : $_GET['limit'];

$dbConn = new mysqli('localhost', 'tharanga', 'qwerty', 'test');

$queryExecerFactory = new QueryExecerFactory($dbConn, $page, $limit);
$queryExecer = $queryExecerFactory->getQueryExecer();

/** @var \mysqli_result $resultset */
$resultset = $queryExecer->query($sql);
//while($row = $resultset->fetch_assoc()) {
//    $records[] = $row;
//}

$pagination = '';
foreach($queryExecer->paginationProvider()->pages() as $page) {
    if ($page->isCurrentPage()) {
        $pagination .= " {$page->getDisplayValue()} ";
        continue;
    }

    $pagination .= " <a href='?page={$page->getPageNumber()}&limit={$limit}'>{$page->getDisplayValue()}</a> ";
}

echo $pagination;

The Versions

15/07 2018

dev-task/TSK-156-decoupled

dev-task/TSK-156-decoupled

Simple pagination module where it accepts a database connection to provide pagination support. Also supports plain pagination.

  Sources   Download

The Requires

  • php >=5.3

 

The Development Requires

by Tharanga Kothalawala

31/08 2016

dev-master

9999999-dev

Simple pagination module where it accepts a database connection to provide pagination support

  Sources   Download

The Requires

  • php >=5.3.3

 

The Development Requires

by Tharanga Kothalawala

31/07 2016

v1.1.0

1.1.0.0

Simple pagination module where it accepts a database connection to provide pagination support

  Sources   Download

The Requires

  • php >=5.3

 

The Development Requires

by Tharanga Kothalawala

21/11 2015

v1.0.0

1.0.0.0

Simple pagination module where it accepts a database connection to provide pagination support

  Sources   Download

The Requires

  • php >=5.3

 

by Tharanga Kothalawala