Pagination is essentially the process of taking a set of results and spreading
them out over pages to make them easier to view.

Its always possible that your SQL SELECT statement query may result into thousand of records. But its is not good idea to display all the results on one page.
So we can divide this result into many pages as per requirement.

Paging means showing your query result in multiple pages instead of just put them all in one long page.

MySQL helps to generate paging by using LIMIT clause which will take two arguments. First argument as OFFSET and second argument how many records should be returned
from the database.

Below is a simple example to fetch records using LIMIT clause to generate paging.

There are three files index.php, funcion.php and database file.

config.php //start here

//php code start here

define (“DB_HOST”, “localhost”); // Your database host name
define (“DB_USER”, “root”); // Your database user
define (“DB_PASS”,””); // Your database password
define (“DB_NAME”,””); // Your database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(“Couldn’t make connection.”);
$db = mysql_select_db(DB_NAME, $link) or die(“Couldn’t select database”);

//config.php end here
index.php //start here

//php start here
include_once “dbConfig.php”;
$i = 1;
$start = 0;
$limit = 50;

$page = $_GET[‘id’];
if (!$page)$page = 0;
else $page–; //first page become 0 instead of 1
$serial = ($page * $limit) + 1;
if (isset($_GET[‘id’])) {
$id = $_GET[‘id’];
$start = ($id – 1) * $limit;
}

// Your SQL query go here. This query will display all record by setting the Limit.

$sql = “SELECT * FROM TABLE_NAME where status = 1 LIMIT “.$pageLimit.” , “.$setLimit;
$query = mysql_query($sql);

while ($rec = mysql_fetch_array($query)) {
//php end here

}
//close div here
//php start here
//Pagination start here.

$rows = mysql_num_rows(mysql_query(“SELECT * FROM TABLE_NAME where status = 1 “));
$setLastpage = ceil($total/$per_page);
$total = ceil($rows / $limit);
//php end here

//php start here
// if ($id > 1) {
echo “Prev”;
}
if ($id != $total) {
echo “Next”;
}echo ” “;

      for ($i = 1; $i <= $total; $i++) {
      if ($i == $id) {
      echo  $i  ;

} else {
echo  $i  ;

}
}
echo ” “;

}
//php end here