PHP code example of hadi / paginate

1. Go to this page and download the library: Download hadi/paginate 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/ */

    

hadi / paginate example snippets




$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();

<br><br>
Total records: <?= $paginate->totalRecord()