PHP code example of tharangakothalawala / resultsetpaginator
1. Go to this page and download the library: Download tharangakothalawala/resultsetpaginator 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/ */
tharangakothalawala / resultsetpaginator example snippets
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;
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;
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;