hadi / paginate
Simple pagination class
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=5.3.0
- hadi/database: ^1.0
This package is auto-updated.
Last update: 2024-11-18 21:36:15 UTC
README
composer require hadi/paginate
Usage
require_once __DIR__ . '/../vendor/autoload.php'; $config = [ 'host' => 'localhost', 'name' => 'abworkout', 'username' => 'root', 'password' => '', ]; $db = new \Hadi\Database(); // https://github.com/im4aLL/pdo-mysql-driver $db->connect($config); $total = $db->query("SELECT id FROM orders")->get(); $paginate = new \Hadi\Paginate([ 'per_page' => 1, 'page_param' => 'page', 'page_url' => 'http://localhost/paginate/test/', 'total_record' => count($total), ]); $orders = $db->query("SELECT * FROM orders ".$paginate->limit())->get(); echo $paginate->limit().' <br><br>'; foreach($orders as $order) { echo $order->id.' - '; echo $order->order_number; echo '<br>'; } $db->disconnect();
More usage
<br><br> Total records: <?= $paginate->totalRecord() ?> <hr> Page <?= $paginate->currentPage() ?> of <?= $paginate->totalPage() ?> <hr> <a href="<?= $paginate->previousPageUrl() ?>">Previous page</a> <a href="<?= $paginate->nextPageUrl() ?>">Next page</a> <hr> <a href="<?= $paginate->firstPageUrl() ?>">First page</a> <a href="<?= $paginate->lastPageUrl() ?>">Last page</a> <hr> <?php foreach($paginate->pages() as $page) { if($page['number']) { echo ' <a href="'.$page['url'].'">'.$page['number'].'</a> '; } else { echo ' ... '; } }