PHP Classes

Simple PHP Pagination Class: Display paginated database table records

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 636 This week: 1All time: 5,004 This week: 560Up
Version License PHP version Categories
simplephppagination 1.0.2BSD License5HTML, PHP 5, Databases
Description 

Author

This class can display paginated database table records.

It takes a PDO object and performs queries to retrieve records for a given database table.

The class can generate pagination links to browse the results with a limited number of records per page.

Picture of NoobSaiboT TheFreakative (iTs)
Name: NoobSaiboT TheFreakative ... <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 2974411 in United States United States
Week rank: 411 Up48 in United States United States Up

Example

<!-- TEST PAGE USING BOOTSTRAP -->
<!DOCTYPE html>
<html>
<head>
    <title> Bootstrap Test </title>
    <link rel='stylesheet' href='css/bootstrap.min.css'>
</head>
<body>
    <section class='container-fluid'>
        <section style='text-align:center;' class='jumbotron'>
            <h1> Bootstrap Example </h1>
            <?php
                error_reporting
(E_ALL ^ E_NOTICE);
               
ini_set("display_errors",1);
               
//!important ---- require the config file and the Pagination class
               
require "config.php";
                include
"Pagination.class.php";
               
//initialize PDO connection and save object to $d
               
try{
                   
$db=new PDO(DSN,USER,PASS);
                }catch(
PDOException $e){
                    echo
"couldn't connect cos of $e";
                }
               
//pass the pdo object,the number of listings per page, and the table name to the class.
               
$paginate = new Pagination($db,5,"customers");
               
//call the paginate methods
               
$test =$paginate->paginate();
               
//print out the returned result
               
echo $test;
           
?>

        </section>
    </section>
</body>
</html>

   



Details

<p align="center"> <img align="center" src="pag.png" width="100%" alt="pagination sample"/> </p>

Simple Pagination Class

This is a simple class that implements pagination when connected to a mysql databse via PDO.

- Include the class - Set the name of your table, number of items per page - edit the ouputted html however you want and voila !

It is really easy to set up. No hassle or stress.

Requirements

To work properly, the class needs:

  • PHP 5 and above, (tested on PHP 7 but should work flawlessly on PHP 5)
  • Web server with PHP and mySQL installed

Installation

This class requires PHP 5 + to run.

Download and extract (https://github.com/sayopaul/paginationclass).

Set your config.php file

<?php
	//set your database comnfiguration here. Ensure to fill in the username and password if there is any.
	define("DSN","mysql:host=dbhost;dbname=dbname");
	define("USER","username");
	define("PASS","password");

After that, you create a new PDO object with the config details

<?php
		//!important ---- require the config file and the Pagination class
		require "config.php";
		include "Pagination.class.php";
		//initialize PDO connection and save object to $db
		try{
			$db=new PDO(DSN,USER,PASS);
		}catch(PDOException $e){
			echo "could not connect because of " .$e ;
		}
		//pass the pdo object,the number of listings per page, and the table name to the class. 
		$paginate = new Pagination($db,5,"customers");
		//call the paginate methods
		$test =$paginate->paginate();
		//print out the returned result
		echo $test;

There's a test file using bootstrap that shows a proper example

Development

Want to contribute? Great! Please star and help to identify areas to improve. Thanks

License

MIT

Free Software, Hell Yeah!


  Files folder image Files  
File Role Description
Files folder imagecss (1 file)
Accessible without login Plain text file config.php Conf. Configuration script
Accessible without login Plain text file database.sql Data Auxiliary data
Accessible without login Image file pag.png Data Auxiliary data
Plain text file Pagination.class.php Class Class source
Accessible without login Plain text file readme.md Doc. Documentation
Accessible without login Plain text file test.php Example Example script

  Files folder image Files  /  css  
File Role Description
  Accessible without login Plain text file bootstrap.min.css Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:636
This week:1
All time:5,004
This week:560Up
User Comments (1)