PHP code example of voku / pagination

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

    

voku / pagination example snippets


use voku\helper\Paginator;

// include the composer-autoloader
r a number of records

// display the records here

echo $pages->page_links();

SELECT * FROM table $pages->get_limit()

echo $pages->page_links('&');

echo $pages->page_links('?' . 'status=' . $_GET['status'] . '&active=' . $_GET['active'] . '&');

use voku\helper\Paginator;

// include the composer-autoloader
pages = new Paginator(10, 'p');

// get number of total records
$rowCount = $db->query('SELECT count(*) FROM table');

// pass number of records to
$pages->set_total($rowCount); 

$data = $db->query('SELECT * FROM table ' . $pages->get_limit());
foreach($data as $row) {
  // display the records here
}

// create the page links
echo $pages->page_links();

use voku\helper\Paginator;

// create a new object
$pages = new Paginator(10, 'p');

// set the total records, calling a method to get the number of records from a model
$pages->set_total( $this->_model->get_all_count() );

// calling a method to get the records with the limit set
$data['records'] = $this->_model->get_all( $pages->get_limit() );

// create the nav menu
$data['page_links'] = $pages->page_links();

// then pass this to the view, may be different depending on the system
$this->_view->render('index', $data);

use voku\helper\Paginator;

// include the composer-autoloader
pages = new Paginator(10, 'p');

// get number of total records
$rowCount = $db->query('SELECT COUNT(*) FROM table');

// pass number of records to
$pages->set_total($rowCount); 

$data = $db->query('SELECT * FROM table ' . $pages->get_limit());
foreach($data as $row) {
  // display the records here
}

// create the api-call
header('Content-Type: application/json');
echo json_encode($pages->page_links_raw());

use voku\helper\Paginator;

// include the composer-autoloader
;

$data = array('some', 'kind', 'of', 'data');

// use the helper-class to reduce the number of pages
$result = PaginatorHelper::reduceData($data, $perPage, $page);

// create the api-call
header('Content-Type: application/json');
echo json_encode($pages->page_links_raw());