1. Go to this page and download the library: Download leoshtika/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/ */
leoshtika / pagination example snippets
eoshtika\libs\Pagination;
use leoshtika\libs\Sqlite;
use leoshtika\libs\UserFaker;
$sqliteFile = 'demo.sqlite';
// Create a new sqlite db if not exists and load some dummy data.
// After the database is created, you don't need this line of code anymore
UserFaker::create($sqliteFile, 120);
$dbh = Sqlite::connect($sqliteFile);
// Get the total number of records
$totalRecords = $dbh->query('SELECT count(*) FROM user')->fetch(PDO::FETCH_COLUMN);
// Instantiate the Pagination
$pagination = new Pagination($_GET['page'], $totalRecords, 10);
// Get records using the pagination
$sth = $dbh->prepare('SELECT * FROM user LIMIT :offset, :records');
$sth->bindValue(':offset', $pagination->offset(), PDO::PARAM_INT);
$sth->bindValue(':records', $pagination->getRecordsPerPage(), PDO::PARAM_INT);
$sth->execute();
$users = $sth->fetchAll(PDO::FETCH_OBJ);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.