PHP code example of metarush / pagination
1. Go to this page and download the library: Download metarush/pagination 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/ */
metarush / pagination example snippets
use MetaRush\Pagination\Builder;
// define minimum : 1;
$path = '/demo.php?page=';
$totalItems = 50;
$itemsPerPage = 5;
$p = (new Builder)
->setTotalItems($totalItems)
->setItemsPerPage($itemsPerPage)
->setCurrentPage($currentPage)
->setPath($path)
->build();
echo $p->prevLink() . ' ' . $p->pageLinksUncut() . ' ' . $p->nextLink();
->setPageLink('<option>{{page}}</option>')
->setActiveLink('<option selected="selected">{{page}}</option>')
->build();
echo $p->prevLink() . ' <select id="myDropdown">' . $p->pageLinksUncut() . '</select> ' . $p->nextLink();
->setPagesCutoff(5) // Estimated max number of page links to display (default: 7)
->build();
echo $p->prevLink() . ' ' . $p->pageLinksAutoCut() . ' ' . $p->nextLink();
->setPageLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">{{page}}</a></li>')
->setActiveLink('<li class="page-item active"><span class="page-link">{{page}}</span></li>')
->setDisabledPrevLink('<li class="page-item disabled"><span class="page-link">Prev</span></li>')
->setDisabledNextLink('<li class="page-item disabled"><span class="page-link">Next</span></li>')
->setEllipsis('<li class="page-item"><span class="page-link">...</span></li>')
->setPrevLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">Prev</a></li>')
->setNextLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">Next</a></li>')
->build();
echo '<ul class="pagination">' . $p->prevLink() . ' ' . $p->pageLinksAutoCut() . ' ' . $p->nextLink().' </ul>';
$limit = $itemsPerPage;
$offset = ($itemsPerPage * $currentPage) - $itemsPerPage;
$sql = "SELECT * FROM your_table LIMIT $limit OFFSET $offset";
$result = DB::table('your_table')
->offset($offset)
->limit($limit)
->get();
$queryBuilder
->select('*')
->from('your_table')
->setFirstResult($offset)
->setMaxResults($limit);