PHP Pagination Creation with OOP


At First you need to create a file called “Pagination.php”
then paste code in this file bilow:

class Pagination extends db {

public $perpage = 0;
public $numberOfPages;
public $numRows;
public $totalRows;
public $tableName;
public $active;

public function __construct($pageNumber,$tableName){

$this->tableName = $tableName;

$this->perpage = $pageNumber;

$this->totalRows = $this->query("select * from `$tableName`");

$this->num_row = $this->num_rows($this->totalRows);

$this->numberOfPages = ceil($this->num_row/$this->perpage);


public function viewList($pageNo){
$limitStart = $this->perpage * ($pageNo-1);
$this->query = $this->query("select * from `$this->tableName` limit $limitStart,$this->perpage");
$this->active = $pageNo;
return $this->query;

public function pagination($pageName,$view,$pg){

$a = "

    if($pg != '1')
    $b = $pg-1 ;
    $b = '1';

$c = "'>

$d = "";

for($i = 1; $i <= $this->numberOfPages; $i++)
if($this->active == $i)
$d .= "


$d .= "



$e ="

Pages 1 of $this->numberOfPages


return $pagination = $a.$b.$c.$d.$e.$f.$g;



Now in which page you want to use pagination you just need to include a this page and make an object.

$pag = new Pagination(10,"shipment");

// here $pag is an object of class called Pagination
// 10 is row per page,
// "shipment" is the table name. from which table you want to show list.

Now use $pag->viewList($_GET['pg']);
to show the paginated row list.
// $_GET['pg'] no is the sagmented individual page no.

Then use $pag->pagination("orders","view",$_GET['pg']);
// "order" is name of the page that you want to use pagination
// "view" is the get method variable eg. $_GET['view']
// $pg is current page no
// i mean to say the path was ""





Base Url Custom Function in PHP

i have created a custom function for printing the base url (url up to the current file from the server name).
here you can try .


public function base_url(){
$this->base_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
return 'http://'.$this->base_url;



<a href="<?php echo 'base_url();' ?>"> this is base url </a>


(if your site running in server)

(if your site running in localhost)