PHP (Core & Framework)

How to implement Pagination with PHP and MySql

paging in php

What is Pagination?

Paging means displaying all your record in multiple pages instead of showing them all on one page. It will minimize the time to load the page.

 $page_size=5;  // define page size (no of records per page)
  $page_no=$_GET['page_no'];    // get current page number
   if (isset($page_no))
   		{ $offset=$page_no * $page_size;  }
  		{ $offset=0;  }  
	$str1="limit $offset, $page_size";

// sql query for Pagination
$sql = "SELECT * FROM table ".$str1;
// write your code to display fetched data from your table

Paging Links

<p align="center">                               
			$query="SELECT * FROM table";
			$result = mysql_query($query); 
			if ($pages>1) 
				for ($i=0;$i<$pages;++$i)
					echo " ";   
					if (!isset($_REQUEST['sdate']))
					   echo "<a href=software_jobs.php?act=$act&page_no=$i>".($i+1)."</a>";


This is the simplest way to show page numbers like 1 2 3 4 5 … , you can modify the code to display like Prev Next or any other way , you wish to show paging links or buttons