A PHP function to generate paginated links using Bootstrap HTML markup
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
pagination.php

README.md

Installation

Simply require the file pagination.php

require 'pagination.php';

OR you can simply copy the function pagination in above file to your source code.

Usage

$baseUrl = "http://somedomain.com/users";
$totalResults = 150;
$resultsPerPage = 10;
$currentPage = !empty($_GET['page']) && ctype_digit($_GET['page']) ? $_GET['page'] : 1;
echo pagination($baseUrl, $totalResults, $resultsPerPage, $currentPage);

Adding Parameters to query string

By default the paginated links will contain only the ?page= query string. To append additional parameters to this you can pass an associative array of parameters and values as the fifth parameter

$additional_params = ['name'=>'John', 'age'=>18];
echo pagination($baseUrl, $totalResults, $resultsPerPage, $currentPage, $additional_params);

Each paginated link will now contain name=John&age=18&page= as query string.

For additional explanation of this function please visit http://perials.com/a-bootstrap-compatible-pagination-function-in-php-for-database-queries/