PHPackages                             nikserg/pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nikserg/pagination

ActiveLibrary

nikserg/pagination
==================

Pagination, without a database dependency

4.0.1(5y ago)08MITPHPPHP &gt;=7.0.0

Since Dec 2Pushed 5y agoCompare

[ Source](https://github.com/nikserg/pagination)[ Packagist](https://packagist.org/packages/nikserg/pagination)[ RSS](/packages/nikserg-pagination/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (18)Used By (0)

[![Build Status](https://camo.githubusercontent.com/a236bcc19c6e1e5b17c1ad49cb6c4e29a41bd13d3f023e0087b44c15afbd66f2/68747470733a2f2f6170692e7472617669732d63692e6f72672f766f6b752f706167696e6174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/voku/pagination)[![codecov.io](https://camo.githubusercontent.com/2f23428a4bb29d1bf5cb3458b80af72c9e2278b67224a25ebf4503d6488c5099/68747470733a2f2f636f6465636f762e696f2f6769746875622f766f6b752f706167696e6174696f6e2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/voku/pagination?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/10667cc3bf9538cc61bd4b6d1d7e1ef304d2682c5e37f6d67b531c886a1df729/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f67726164652f3435373634383261336663343463643139366235363661343232646139373531)](https://www.codacy.com/app/voku/pagination)[![Latest Stable Version](https://camo.githubusercontent.com/9f0b7881a2f6fb92a44fe9337de88eec9933c9ce6e67e99a35421993aa26ae4d/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f706167696e6174696f6e2f762f737461626c65)](https://packagist.org/packages/voku/pagination)[![Total Downloads](https://camo.githubusercontent.com/5b370f1b2f841c118d6135cd636dcc033beebbb051063d55bbdfb3471e21c059/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f706167696e6174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/voku/pagination)[![License](https://camo.githubusercontent.com/79d070e139260965b131a636560afa6a9024e8fa2cda2621ec4eb177baba91a9/68747470733a2f2f706f7365722e707567782e6f72672f766f6b752f706167696e6174696f6e2f6c6963656e7365)](https://packagist.org/packages/voku/pagination)[![Donate to this project using Paypal](https://camo.githubusercontent.com/0d6e4d8b50b5983a58205941b1a581b1305903393b7a39da574e3f60af3c7f5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e737667)](https://www.paypal.me/moelleken)[![Donate to this project using Patreon](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/voku)

📖 Paginator
===========

[](#-paginator)

Pagination, without (database) dependencies.

Install via "composer require"
------------------------------

[](#install-via-composer-require)

```
composer require voku/pagination
```

Usage
-----

[](#usage)

1. include the composer-autoloader
2. instantiate a new object pass in the number of items per page and the instance identifier, this is used for the GET parameter such as ?p=2
3. pass the set\_total method the total number of records
4. show the records
5. call the page\_links method to create the navigation links

```
use voku\helper\Paginator;

// include the composer-autoloader
require_once __DIR__ . '/vendor/autoload.php';

$pages = new Paginator(10, 'p');
$pages->set_total(100); // or a number of records

// display the records here

echo $pages->page_links();
```

if using a database you limit the records by placing $pages-&gt;get\_limit() in your query, this will limit the number of records

```
SELECT * FROM table $pages->get_limit()
```

by default the page\_links method created links starting with ? this can be changed by passing in a parameter to the method:

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

The method also allows you to pass in extra data such as a series of GET's

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

Database example
----------------

[](#database-example)

```
use voku\helper\Paginator;

// include the composer-autoloader
require_once __DIR__ . '/vendor/autoload.php';

// create new object pass in number of pages and identifier
$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();
```

MVC example
-----------

[](#mvc-example)

using this class in an MVC environment its almost the same, only the database or dataset calls come from the model instead of the page directly.

in the controller:

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

API example (with Database)
---------------------------

[](#api-example-with-database)

```
use voku\helper\Paginator;

// include the composer-autoloader
require_once __DIR__ . '/vendor/autoload.php';

// create new object pass in number of pages and identifier
$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());
```

API example (with Array)
------------------------

[](#api-example-with-array)

```
use voku\helper\Paginator;

// include the composer-autoloader
require_once __DIR__ . '/vendor/autoload.php';

$page = (int)$_GET['page'];
$perPage = (int)$_GET['per_page'];

$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());
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 91.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~130 days

Recently: every ~405 days

Total

16

Last Release

1856d ago

Major Versions

1.0.2 → 2.0.02016-03-02

2.1.7 → 3.0.02018-06-10

3.0.1 → 4.0.02020-03-20

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b03ce989f89fc2cc42dc6847d51f517a6e40f3dddde319060169a933e4bc0c77?d=identicon)[nikserg](/maintainers/nikserg)

---

Top Contributors

[![voku](https://avatars.githubusercontent.com/u/264695?v=4)](https://github.com/voku "voku (43 commits)")[![daveismynamecom](https://avatars.githubusercontent.com/u/60222583?v=4)](https://github.com/daveismynamecom "daveismynamecom (3 commits)")[![nikserg](https://avatars.githubusercontent.com/u/5680589?v=4)](https://github.com/nikserg "nikserg (1 commits)")

---

Tags

pagerpaginatorpagination

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nikserg-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/nikserg-pagination/health.svg)](https://phpackages.com/packages/nikserg-pagination)
```

###  Alternatives

[knplabs/knp-paginator-bundle

Paginator bundle for Symfony to automate pagination and simplify sorting and other features

1.8k42.8M315](/packages/knplabs-knp-paginator-bundle)[jasongrimes/paginator

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

4101.3M21](/packages/jasongrimes-paginator)[ashleydawson/simple-pagination

Simple, lightweight and universal service that implements pagination on collections of things

18161.2k2](/packages/ashleydawson-simple-pagination)[data-dog/pager-bundle

Paginator bundle for symfony2 and doctrine orm, allows customization with filters and sorters

11103.5k7](/packages/data-dog-pager-bundle)[ttskch/paginator-bundle

The most thin, simple and customizable paginator bundle for Symfony

1113.2k](/packages/ttskch-paginator-bundle)[sivka/paginator

bootstrap-4 fork of jasongrimes/php-paginator, a lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

141.3k](/packages/sivka-paginator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
