2017 © Pedro Peláez
 

library pagination

The simpliest PHP pagination class

image

leoshtika/pagination

The simpliest PHP pagination class

  • Sunday, February 21, 2016
  • by leoshtika
  • Repository
  • 2 Watchers
  • 4 Stars
  • 39 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

The simplest PHP pagination class

License Packagist, (*1)

Requirements

  • PHP 5.3 or higher

Installation with Composer

  • from the command line
composer require leoshtika/pagination
  • or updating your composer.json file
{
    "require": {
        "leoshtika/pagination": "~1.0"
    }
}

Usage

Connect to an SQLite database

query('SELECT count(*) FROM user')->fetch(PDO::FETCH_COLUMN);

// Instantiate the Pagination
$pagination = new Pagination($_GET['page'], $totalRecords, 10);

// Get records using the pagination
$sth = $dbh->prepare('SELECT * FROM user LIMIT :offset, :records');
$sth->bindValue(':offset', $pagination->offset(), PDO::PARAM_INT);
$sth->bindValue(':records', $pagination->getRecordsPerPage(), PDO::PARAM_INT);
$sth->execute();
$users = $sth->fetchAll(PDO::FETCH_OBJ);

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Pagination</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
</head>
<body class="container-fluid">

    <h1>Pagination!</h1>
    <table class="table table-bordered table-hover">
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Address</th>
            <th>Phone</th>
        </tr>
        <?php foreach ($users as $user) : ?>
            <tr>
                <td><?php echo $user->id; ?></td>
                <td><?php echo $user->name; ?></td>
                <td><?php echo $user->email; ?></td>
                <td><?php echo $user->address; ?></td>
                <td><?php echo $user->phone; ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
    <?php echo $pagination->nav(); ?>
</body>
</html>

Enjoy!, (*2)

The Versions

21/02 2016

dev-master

9999999-dev

The simpliest PHP pagination class

  Sources   Download

MIT

The Requires

 

The Development Requires

21/02 2016

dev-develop

dev-develop

The simpliest PHP pagination class

  Sources   Download

MIT

The Requires

 

The Development Requires

21/02 2016

v1.0.1

1.0.1.0

The simpliest PHP pagination class

  Sources   Download

MIT

The Requires

 

The Development Requires

21/02 2016

v1.0.0

1.0.0.0

The simpliest PHP pagination class

  Sources   Download

MIT

The Requires

 

The Development Requires

01/03 2015

v0.0.1

0.0.1.0

The simpliest PHP pagination class

  Sources   Download

MIT

The Requires

 

The Development Requires