A lightweight and easy-to-use PHP pagination class fully compatible with Bootstrap 4. This package helps developers paginate large datasets and display responsive pagination controls with minimal setup.
- Bootstrap 4 compatible pagination
- Easy integration with PHP & MySQL
- Custom items per page support
- Jump menu navigation
- Responsive pagination links
- Lightweight and reusable class
- PHP 5.6+
- MySQL Database
- Bootstrap 4
composer require learncodeweb/php-pagination-class-with-bootstrap-4:dev-master- Download the repository.
- Extract files into your project directory.
- Include the pagination class in your PHP file.
include_once('paginator.class.php');Create a database connection file (config.php).
<?php
define('DB_NAME', 'test');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
?>Include required files:
<?php
include_once('config.php');
include_once('paginator.class.php');
?>Initialize pagination:
$pages = new Paginator();
$pages->default_ipp = 15;
$query = $db->query("SELECT * FROM countries");
$pages->items_total = $query->num_rows;
$pages->mid_range = 9;
$pages->paginate();Fetch paginated records:
$result = $db->query(
"SELECT * FROM countries ORDER BY countryName ASC " . $pages->limit
);<?php
echo $pages->display_pages();
echo $pages->display_items_per_page();
echo $pages->display_jump_menu();
?><table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['countryName']; ?></td>
<td><?php echo $row['countryCode']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>| Method | Description |
|---|---|
paginate() |
Generate pagination |
display_pages() |
Display page links |
display_items_per_page() |
Display items per page selector |
display_jump_menu() |
Display jump menu |
limit |
SQL LIMIT clause |
| Property | Description |
|---|---|
default_ipp |
Items per page |
items_total |
Total records |
mid_range |
Number of pagination links shown |
Example:
$pages->default_ipp = 20;
$pages->mid_range = 7;project/
│
├── config.php
├── index.php
├── paginator.class.php
└── assets/
MIT License