2017 © Pedro Peláez
 

library t2-simple-pagination

image

faurelia/t2-simple-pagination

  • Tuesday, May 1, 2018
  • by faurelia
  • Repository
  • 0 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

T2 Simple Pagination

A Simple PHP Pagination library (with Bootstrap 3 example), (*1)

Installation

require_once '/path/to/t2-simple-pagination/T2SimplePagination.php';

Usage

Initialize T2SimplePagination providing the 2 required parameters, total and page as well as additional settings., (*2)

// get the current page
$page = isset($_GET['p']) ? $_GET['p'] : 1;

// count total data from your record source. ie: DB or a file
$total = DB::count($data);

// set the number of items to display per page
$per_page = 10;

// set the number of page links to display
$range = 7; // IMPORTANT: please use odd numbers ONLY!!!

$pagination = new T2SimplePagination($total, $page, $per_page, $range);

Then extract the records by using the offset and per_page properties., (*3)

$query = "SELECT * FROM my_table LIMIT {$pagination->offset}, {$pagination->per_page}"

See the class Properties below for more details., (*4)

<?php for ($i = $pagination->min_page; $i <= $pagination->max_page; $i++): ?>
<a href="?p=<?php echo $i ?>">
    <?php echo $i ?>
</a>
<?php endfor; ?>
prev_page): ?>
    <a href="?p=<?php echo $pagination->prev_page ?>">Prev</a>

    Prev


next_page): ?>
    <a href="?p=<?php echo $pagination->next_page ?>">Next</a>

    Next

You may want to hide the pagination links when there is only one page, so it is recommended to enclose the above codes inside this if block:, (*5)

num_page): ?>
    // pager or page links

For Bootstrap 3 example, please check the index.php file included in this repository., (*6)

Properties

Variables Description
total the total number of records to be paginated
page the current page, default: 1
per_page the number of items to display per page, default: 10
num_page the total number of pages
offset the current record pointer
next_page the next page if page is not equals to num_page
prev_page the previous page if page is not 1
range the number of page links to display, default: 5 (Note: Use ODD numbers only!)
min_page the start page in the page links
max_page the end page in the page links

License

This library is distributed under MIT License. © 2017 Fatima Aurelia, (*7)

The Versions

01/05 2018

v1.0.0

1.0.0.0

  Sources   Download

05/03 2018

dev-master

9999999-dev https://github.com/faurelia/t2-simple-pagination

A simple PHP pagination (with Bootstrap 3 example)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

pagination php pagination

04/08 2017

v1.0.1

1.0.1.0 https://github.com/faurelia/t2-simple-pagination

A simple PHP pagination (with Bootstrap 3 example)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

pagination php pagination