PHP Example
Screen shot
Advance Pagination Script

<?php

$conn=mysql_connect('localhost','root','') or die('Mysql Not connected');

$database=mysql_select_db('test',$conn) or die('Database Not connected');

 

$limit=5;

 

$page_size=10;

 

if(isset($_REQUEST['start']))

$start_no=$_REQUEST['start']-$page_size*$limit;

else

$start_no=0;

 

 

 

$i=0;

 

if(isset($_REQUEST['page_no']))

$page_no=$_REQUEST['page_no']-$limit;

else

$page_no=1;

 

$query1="SELECT * FROM tbl_ads limit $start_no,$page_size";

$query2="SELECT * FROM tbl_ads";

 

$result1=mysql_query($query1);

$result2=mysql_query($query2);

 

$total_records=mysql_num_rows($result2);

?>

<html>

<head>

<title>PHP Example</title>

</head>

<body>

<table width="500" border='1'>

<tr>

<th>Sno</th>

<th>Ad Title</th>

<th>Ad City</th>

</tr>

<?php

while($row=mysql_fetch_array($result1))

{

$i++;

?>

<tr>

<td><?php echo $i; ?></td>

<td><?php echo $row['ad_title']; ?></td>

<td><?php echo $row['ad_city']; ?></td>

</tr>

<?php

}

?>

</table>

<table width="500"  border='0'>

<tr>

<td><a href='index.php'>First</a>&nbsp;

<a href='index.php?start=<?php echo $start_no-$page_size; ?>&page_no=<?php echo $page_no; ?>'>Prev</a></td>

<?php

$count=0;

for($j=$start_no;$j<$total_records;$j=$j+$page_size)

{

$count++;

if($count>10)

break;

if($start_no==$j)

{

?>

<td><span color='red' style='color:#FF0000'><?php echo $page_no; ?></span></td>

<?php

}

else

{

?>

<td><a href='index.php?start=<?php echo $j; ?>&page_no=<?php echo $page_no; ?>'><?php echo $page_no; ?></a></td>

 

<?php

}

$page_no++;

}

?>

<td>

<a href='index.php?start=<?php echo $start_no+$page_size; ?>&page_no=<?php echo $page_no; ?>'>Next</a>&nbsp;

<a href='index.php?start=<?php echo $j-$page_size; ?>'>Last</a></td>

</tr>

</table>

</body>

</html>

You can download source code here