PHP code example of benjaminmedia / zebra-pagination

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

    

benjaminmedia / 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
age
$pagination->records_per_page($records_per_page);

// 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
);


$pagination->navigation_position('left');

$pagination->navigation_position('right');

$pagination->labels('Previous', 'Next');



// how many records should be displayed on a page?
$records_per_page = 10;

// include the pagination class
ows
// note how we build the LIMIT
// also, note the "SQL_CALC_FOUND_ROWS"
// this is to get the number of rows that would've been returned if there was no LIMIT
// see http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
$sql = '
    SELECT
        SQL_CALC_FOUND_ROWS
        country
    FROM
        countries
    LIMIT
        ' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
';

// execute the MySQL query
// (you will use mysqli or PDO here, but you get the idea)
$result = mysql_query($sql))) or die(mysql_error());

// fetch the total number of records in the table
$rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));

// pass the total number of records to the pagination class
$pagination->records($rows['rows']);

// records per page
$pagination->records_per_page($records_per_page);




// how many records should be displayed on a page?
$records_per_page = 10;

// include the pagination class
ination->reverse(true);

// when showing records in reverse order, we need to know the total number
// of records from the beginning
$result = mysql_query('SELECT COUNT(id) AS records FROM countries'))) or die (mysql_error());

// pass the total number of records to the pagination class
$pagination->records(array_pop(mysql_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
mysql_query($sql) or die(mysql_error());