PHPackages                             ck/pagecalc - 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. ck/pagecalc

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

ck/pagecalc
===========

Calculates page numbers and cursors of paged results

06PHP

Since Aug 27Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/14ff303732ce6e37a0d9c515a2822485fe72f4dc13aee891df0b9004b2901f28/68747470733a2f2f7472617669732d63692e6f72672f634b6c65652f7061676563616c632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cKlee/pagecalc)

PageCalc
========

[](#pagecalc)

It calculates the page number and cursor (first item number on the current page) vice versa.

It also calculates

- next cursor (first item number on the next page if applicable)
- previous cursor (first item number on the previous page if applicable)
- last cursor (first item number on the last page)
- next page number if applicable
- previous page number if applicable
- last page number
- total number of pages

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

[](#installation)

Install with composer:

```
composer require "ck/pagecalc:@dev"

```

Usage example
-------------

[](#usage-example)

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

use CK\PageCalc;

$pc = new PageCalc(20) ; // Initiate with a default number of items on one page (limit)

// Someone makes a request on page 3 and a limit of 20 items on the page
$pc->gotoPage($_GET['page'], $_GET['limit']);

// Now do your query using the cursor (offset)
doYourQuery($query = $_GET['q'], $offset = $pc->getCursor(), $limit = $_GET['limit']);

/*
*  With the results you have a total number of results (e.g. $total = 100)
*/

echo 'There are '. $pc->getTotalPages($total) .' pages'; # There are 5 pages

echo 'Page '. $pc->getPage() . ' starts at ' .$pc->getCursor(); # Page 3 starts at 41

// make sure there is a next page
if($pc->getNextPage($total)) {
    echo 'Next page is '. $pc->getNextPage($total) . ' and starts at ' . $pc->getNextCursor($total); # Next page is 4 and starts at 61
}

// make sure there is a previous page
if($pc->getPreviousPage()) {
    echo 'Previous page was '. $pc->getPreviousPage() . ' and started at ' . $pc->getPreviousCursor(); # Previous page was 2 and started at 21
}

// there is always a last page (same as total number of pages)
echo $pc->getLastPage($total) .' is the last page and starts at '. $pc->getLastCursor($total); # 5 is the last page and starts at 81
```

Methods
-------

[](#methods)

### \_\_construct($limit)

[](#__constructlimit)

Sets the default limit. If limit is lower than one, default limit will be 1.

### moveCursor($cursor, $limit = false)

[](#movecursorcursor-limit--false)

Moves cursor, calcultes page number and optionally sets a new limit

Since cursor is always the first item number on the current page, cursor must be a multitude of the limit plus 1. If cursor number is not correct method moveCursor will correct this. E.g.:

```
$pc = new PageCalc(3); // limit 3
$pc->moveCursor(5); // cursor can't be 5
echo $pc->getCursor(); // current cursor is now 4.
//4 is the first item number on page 2, wich contains item number 5
```

### gotoPage($page, $limit = false)

[](#gotopagepage-limit--false)

Sets the current page number, calculates cursor number and optionally sets a new limit

### getCursor()

[](#getcursor)

Gets the number of the first item on the current page

### getNextCursor($total)

[](#getnextcursortotal)

$total is the total number of items.

Gets the number of the first item on the next page. Returns false if there is no next page.

### getPreviousCursor()

[](#getpreviouscursor)

Gets the number of the first item on the previous page. Returns false if there is no previous page.

### getLastCursor($total)

[](#getlastcursortotal)

$total is the total number of items.

Gets the number of the first item on the last page.

### getPage()

[](#getpage)

Gets the number of the current page

### getNextPage($total)

[](#getnextpagetotal)

$total is the total number of items.

Gets the number of the next page. Returns false if there is no next page.

### getPreviousPage()

[](#getpreviouspage)

Gets the number of the previous page. Returns false if there is no previous page.

### getLastPage($total)

[](#getlastpagetotal)

$total is the total number of items.

Gets the number of last page.

### getTotalPages($total)

[](#gettotalpagestotal)

$total is the total number of items.

Gets the total number of pages.

### getNumberOfItems($total)

[](#getnumberofitemstotal)

$total is the total number of items.

Get number of items on current page.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/23064ee47ef1ea033e3068dc2e1bafb1f1a07c3ddfc3a060010145ba90bc95ed?d=identicon)[collidoscope](/maintainers/collidoscope)

---

Top Contributors

[![cKlee](https://avatars.githubusercontent.com/u/849235?v=4)](https://github.com/cKlee "cKlee (19 commits)")

---

Tags

pagepagedlistpaginationpagination-calculatepaging

### Embed Badge

![Health badge](/badges/ck-pagecalc/health.svg)

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

PHPackages © 2026

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