PHP code example of carry0987 / paginator

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

    

carry0987 / paginator example snippets




use carry0987\Paginator\Paginator;

//Use for loop to create variable $totalItems that have 1000 items
$totalItems = array();
for ($i = 0; $i < 1000; $i++) {
    $totalItems[] = $i;
}
$itemsPerPage = 50;
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 8;
$urlPattern = '?page=(:num)';

$paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);

$get_all_page = $paginator->getPage();
$total_page = $paginator->getTotalPage();
$prev_page = $paginator->getPrevUrl();
$next_page = $paginator->getNextUrl();
$first_page = $paginator->getFirstPageUrl();
$last_page = $paginator->getLastPageUrl();

<html>
    <head>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    </head>
    <body>
        <!---Pagination--->
 if ($total_page > 1) {