Location: PHPKode > scripts > Pagination Advanced > kbpaginationadvanced/kbpaginationadvanced/index.php
<?PHP
include "config.php";
include "function.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
  <title>Free PHP Scripts</title>
  <meta name="description" content="KB Kunal Bansal is a web hub that provides the user with the 

free PHP script, tools, site references ,php hosting, php tools and much more..."/>
  <meta name="keywords" content="web hub, scripts, free php scripts, php, free, php tools, php 

information, php hosting, php softwares,php affiliate script, php theme script, php login script, 

free webspace, free homepage, webpage, website, web site, free web site, web host, web hosting, 

free web host, free web hosting, cheap web host, cheap web hosting, building a web site, hosting 

a web site, web publishing, web site tools, web authoring, Free domain name, domains, site host, 

building a blog, web site creation tools, domain hosting, top hosts, free scripts,compare"/>
  <meta name="ROBOTS" content="ALL"/>
</head>
<link rel="stylesheet" type="text/css" href="style.css" />
<body>

<h1>Pagination</h1>
<p>In Pagination you can distribute number of records on different pages and specify links so that user can go from one page to next page. Generally what user see is First, Previous, Next, Last links along with few page numbers like 1,2,3,4,5 and if he is on page 9 then something like 7,8,9,10,11 or 9,10,11,12,13 etc.<br><br>

But what when there are large number of pages say 1000 and a user wants to go to page number 400 then according to simple pagination he can click on Page 5 then page 7 then 9 (when there are 5 pages being shown) and page 5 then 12 then 19 (when there are 15 pages being shown) etc. and this would take time to reach Page Number 400. So, in such cases we should display more pages also.<br><br>

With this code you will be able to view more pages. Lets take an example. Say there are 10000 records and on each page 10 records are being shown. So, number of pages is 1000. Currently selected Page is 500. So, links shown will be of Page 1,2,3,497,498,499,500,501,502,503,998,999,1000 and pages between 3-497 and 503-998 range with some page number difference. Here, we have taken links to be shown = 3, that is why Page 1,2,3 are showing.<br><br>

Pagination in PHP is easy and you can show advance pagination by following code. There are 4 files (don’t go to the number of files, separate files have been created so that you can easily understand the code), I could have combined it in 1 but 4 seems to be better.<br></p>

<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td>

<?php

$resqry_sub="SELECT * FROM scrpagination";

	$qry_resqry="$resqry_sub";
	$rsl_resqry=mysql_query($qry_resqry);
	$n_resqry = mysql_num_rows($rsl_resqry);
	//$arr_resqry =  mysql_fetch_row($rsl_resqry);
	
	if($n_resqry=='0')
	{
	echo "No results Found";
	}
	else
	{
	$targetpageurl="";
	$total_records=$n_resqry;
	$paging_recordsperpg="5";
	$paging_linksshow="3";
	$paging_linksshowmax="25";

	include_once "paging.php";
	
	$lowerlimit=$paging_recordstart-1;
	$upperlimit=$paging_recordsshowing;
	$limit="LIMIT $lowerlimit, $upperlimit";
	
	$qry_pagination="$resqry_sub $limit";
	$rsl_pagination=mysql_query($qry_pagination);
	$n_pagination = mysql_num_rows($rsl_pagination);
	//$arr_pagination =  mysql_fetch_row($rsl_pagination);
	
	if($n_pagination=='0')
	{
	echo "<tr><td class='count'>";
	echo "No results Found";
	echo "</td></tr>";
	}
	else
	{
	
	echo "<tr><td class='count'>";
	if($n_pagination!='')
	{
	echo "$n_resqry Records";
	}
	else
	{
	echo "$n_resqry Records";	
	}	
	echo "</td></tr>";

	echo "<tr><td>";
		
//echo "<div class='paging'>";
echo "<div class='paging_displaying'>Displaying Page $paging_currentpg (of $paging_pages) and $paging_recordsshowing Records (of $total_records Total Records)</div>";
echo "<div class='paging'>$paging_navigation</div>";
echo "<div>";


		$dsplycolnum="1";
		$dsplycolcount="0";
	
	for($i=1; $i<=$n_pagination; $i++)
	{	
	$arr_pagination =  mysql_fetch_row($rsl_pagination);	

	echo "$arr_pagination[1]<br>";
	}
echo "</div>";	
	
echo "<div class='paging'>$paging_navigation</div>";
}
}		
?>	
	
</td>
</tr>

</table>


</body>
</html>
Return current item: Pagination Advanced