hadi/paginate

Simple pagination class

Installs: 50

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:package

1.0.0 2017-09-10 12:29 UTC

This package is auto-updated.

Last update: 2024-10-18 21:22:26 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 ' ... ';
    }
}