PHPackages                             delight-im/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. delight-im/pagination

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

delight-im/pagination
=====================

Helps partition items across pages and generates sets of convenient controls for navigation

v1.0.0(1y ago)410MITPHPPHP &gt;=5.6.0

Since Jul 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/delight-im/PHP-Pagination)[ Packagist](https://packagist.org/packages/delight-im/pagination)[ Docs](https://github.com/delight-im/PHP-Pagination)[ RSS](/packages/delight-im-pagination/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP-Pagination
==============

[](#php-pagination)

Helps partition items across pages and generates sets of convenient controls for navigation

Requirements
------------

[](#requirements)

- PHP 5.6.0+

Installation
------------

[](#installation)

1. Include the library via Composer [\[?\]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md):

    ```
    $ composer require delight-im/pagination
    ```
2. Include the Composer autoloader:

    ```
    require __DIR__ . '/vendor/autoload.php';
    ```

Usage
-----

[](#usage)

### Creating an instance

[](#creating-an-instance)

```
$numberOfItems = 1000;
$pagination = new Pagination($numberOfItems);

// or

$numberOfItems = 1000;
$itemsPerPage = 30;
$pagination = new Pagination($numberOfItems, $itemsPerPage);

// or

$numberOfItems = 1000;
$itemsPerPage = 30;
$currentPage = 10;
$pagination = new Pagination(
    $numberOfItems,
    $itemsPerPage,
    $currentPage
);
```

If you don’t specify the current page explicitly in the third argument, it will be auto-detected from the `page` or `p` query parameters, if available.

### Displaying a pagination bar

[](#displaying-a-pagination-bar)

#### Simple HTML

[](#simple-html)

```
$targetUrl = '/products/drinks/?page={page}';
echo $pagination->toHtml($targetUrl);

// or

$targetUrl = '/products/drinks/?page={page}';
$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
echo $pagination->toHtml(
    $targetUrl,
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

#### Bootstrap front-end framework

[](#bootstrap-front-end-framework)

```
$targetUrl = '/products/drinks/?page={page}';
echo $pagination->toHtmlForBootstrap5($targetUrl);

// or

$targetUrl = '/products/drinks/?page={page}';
$displaySize = 0; // -1 = small, 0 = normal, +1 = large
$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
echo $pagination->toHtmlForBootstrap5(
    $targetUrl,
    $displaySize,
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

Instead of `Pagination#toHtmlForBootstrap5`, you can also call `Pagination#toHtmlForBootstrap4` or `Pagination#toHtmlForBootstrap3` with the same method signature.

#### Custom HTML

[](#custom-html)

First, generate an array of `PaginationElement` objects:

```
$controls = $pagination->build();

// or

$numberOfControls = 11;
$showFirstLast = true;
$showPreviousNext = true;
$previousLabel = '« Previous';
$nextLabel = 'Next »';
$controls = $pagination->build(
    $numberOfControls,
    $showFirstLast,
    $showPreviousNext,
    $previousLabel,
    $nextLabel
);
```

Then turn these `PaginationElement` objects into custom HTML:

```
foreach ($controls as $control) {
    // $control->getLabel();
    // $control->getPage();
    // $control->isSelected();
    // $control->isDisabled();
}
```

### Adjusting database queries

[](#adjusting-database-queries)

```
$pagination->getOffset();
// int(1000)

$pagination->getLimit();
// int(25)
```

You can use these two values in your database queries, for example like this:

```
$sql = "SELECT * FROM products LIMIT " . $pagination->getOffset() . ", " . $pagination->getLimit();

// or

$sql = "SELECT * FROM products LIMIT " . $pagination->getLimit() . " OFFSET " . $pagination->getOffset();
```

Contributing
------------

[](#contributing)

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

License
-------

[](#license)

This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

663d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cabc03c705598aed200d843d4e5b1c6350729b060cc61ec8a1bb14e02e5c0a32?d=identicon)[delight-im](/maintainers/delight-im)

---

Top Contributors

[![ocram](https://avatars.githubusercontent.com/u/1681478?v=4)](https://github.com/ocram "ocram (1 commits)")

---

Tags

pagepaginatorpaginationpaging

### Embed Badge

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

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

###  Alternatives

[pagerfanta/pagerfanta

Pagination for PHP

42550.0M245](/packages/pagerfanta-pagerfanta)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163612.6k11](/packages/beberlei-porpaginas)[coffeecode/paginator

Paginator is simple and is ready to generate results navigation in your application

59658.1k1](/packages/coffeecode-paginator)[stefangabos/zebra_pagination

A generic, Twitter Bootstrap compatible, PHP pagination library that automatically generates navigation links

11122.9k](/packages/stefangabos-zebra-pagination)[usmanhalalit/strana

Pagination library for PHP, framework agnostic, with built-in adapters for Doctrine, Eloquent, Pixie and PHP Array.

947.4k3](/packages/usmanhalalit-strana)[lampager/lampager-laravel

Rapid pagination for Laravel

7641.4k](/packages/lampager-lampager-laravel)

PHPackages © 2026

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