PHP code example of catlabinteractive / cursor-pagination
1. Go to this page and download the library: Download catlabinteractive/cursor-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/ */
catlabinteractive / cursor-pagination example snippets
use CatLab\Base\Models\Database\OrderParameter;
use CatLab\CursorPagination\CursorPaginationBuilder;
ecords on each page
$builder->limit(isset($_GET['records']) ? $_GET['records'] : 5);
// Register properties
$builder->registerPropertyName('id', 'public_id');
$builder->registerPropertyName('name', 'public_name');
$builder->registerPropertyName('score', 'public_score');
/**
* Set select order
*/
// Order by score desc
$builder->orderBy(new OrderParameter('score', OrderParameter::DESC));
// Same score? Order by name asc
$builder->orderBy(new OrderParameter('name', OrderParameter::ASC));
// Same score and same name? Sort on ID
$builder->orderBy(new OrderParameter('id', OrderParameter::ASC));
// Set the request parameters
$builder->setRequest($_GET);
/**
* Select and output data
*/
// Build the select query
$query = $builder->build();
// Load the data
$sql = $query->toQuery($pdo, 'entries');
$results = $pdo->query($sql)->fetchAll();
// Post process results. Very important. Don't forget.
$results = $builder->processResults($query, $results);
// Display the records
$table = new Table([ 'id', 'name', 'score' ]);
$table->open();
foreach ($results as $v) {
$table->row($v);
}
$table->close();
$table->navigation($builder->getNavigation());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.