PHP code example of stefangabos / zebra_pagination
1. Go to this page and download the library: Download stefangabos/zebra_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/ */
stefangabos / zebra_pagination example snippets
// let's paginate data from an array...
$countries = array(
// array of countries
);
// how many records should be displayed on a page?
$records_per_page = 10;
// include the pagination class
// (you don't need this if you are using composer)
);
// here's the magic: we need to display *only* the records for the current page
$countries = array_slice(
$countries,
(($pagination->get_page() - 1) * $records_per_page),
$records_per_page
);
// connect to a database
$connection = mysqli_connect($host, $username, $password, $database);
// how many records should be displayed on a page?
$records_per_page = 10;
// include the pagination class
// (you don't need this if you are using composer)
. $records_per_page . '
';
// execute the MySQL query
// (you will use mysqli or PDO here, but you get the idea)
$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
// fetch the total number of records in the table
$rows = mysqli_fetch_assoc(mysqli_query($connection, 'SELECT COUNT(*) AS rows FROM countries'));
// pass the total number of records to the pagination class
$pagination->records($rows['rows']);
// records per page
$pagination->records_per_page($records_per_page);
// connect to a database
$connection = mysqli_connect($host, $username, $password, $database);
// how many records should be displayed on a page?
$records_per_page = 10;
// include the pagination class
// (you don't need this if you are using Composer)
li_query($connection, 'SELECT COUNT(*) AS rows FROM countries'))) or die (mysqli_error());
// pass the total number of records to the pagination class
$pagination->records(array_pop(mysqli_fetch_assoc($result)));
// records per page
$pagination->records_per_page($records_per_page);
// the MySQL statement to fetch the rows
// note the LIMIT - use it exactly like that!
// also note that we're ordering data descendingly - most important when we're
// showing records in reverse order!
$sql = '
SELECT
country
FROM
countries
ORDER BY
country DESC
LIMIT
' . (($pagination->get_pages() - $pagination->get_page()) * $records_per_page) . ', ' . $records_per_page . '
';
// run the query
mysqli_query($connection. $sql) or die(mysqli_error($connection));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.