1. Go to this page and download the library: Download makedo/php-paginator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
makedo / php-paginator example snippets
$loader = function (int $limit, int $skip): iterable
{
//SELECT * from users WHERE id > $skip LIMIT $limit
};
$perPage = 100;
$lastIdOnPreviousPage = 34;
$paginatorFactory = new SkipById($perPage);
$page = $paginatorFactory
->createPaginator(new CallableLoader($loader), $lastIdOnPreviousPage)
->paginate()
;
$loader = function (int $limit, int $skip): iterable {
//SELECT * from users WHERE id > $skip LIMIT
};
$counter = function (): int {
//SELECT count(id) from users
};
$perPage = 100;
$lastIdOnPreviousPage = 35;
$paginatorFactory = new SkipByIdCountable($perPage);
$page = $paginatorFactory
->createPaginator(
new CallableLoader($loader),
new CallableCounter($counter),
$lastIdOnPreviousPage
)
->paginate()
;
$loader = function (int $limit, int $skip): iterable {
//SELECT * from users WHERE id > $skip LIMIT
};
$counter = function (): int {
//SELECT count(id) from users
};
$perPage = 100;
$lastIdOnPreviousPage = 35;
$currentPage = 4;
$paginatorFactory = new SkipByIdCountable($perPage);
$page = $paginatorFactory
->createPaginator(
new CallableLoader($loader),
new CallableCounter($counter),
$lastIdOnPreviousPage,
$currentPage
)
->paginate()
;
$loader = function (int $limit, int $skip): iterable
{
//SELECT * from users LIMIT $limit OFFSET $skip
};
$perPage = 100;
$currentPage = 2;
$paginatorFactory = new SkipByOffset($perPage);
$page = $paginatorFactory
->createPaginator(new CallableLoader($loader), $currentPage)
->paginate()
;
$loader = function (int $limit, int $skip): iterable {
//SELECT * from users LIMIT $limit OFFSET $skip
};
$counter = function (): int {
//SELECT count(id) from users
};
$perPage = 100;
$currentPage = 2;
$paginatorFactory = new SkipByOffsetCountable($perPage);
$page = $paginatorFactory
->createPaginator(new CallableLoader($loader), new CallableCounter($counter), $currentPage)
->paginate()
;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.