# Making a perfect pagination?

**URL:** <https://forum.kirupa.com/t/making-a-perfect-pagination/174563>\
**Category:** Uncategorized\
**Created:** [January 6, 2006, 6:57pm UTC](https://forum.kirupa.com/t/making-a-perfect-pagination/174563 "2006-01-06T18:57:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PHPycho](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@PHPycho](https://forum.kirupa.com/u/PHPycho)\
**Post date:** [January 6, 2006, 6:57pm UTC](https://forum.kirupa.com/t/making-a-perfect-pagination/174563/1 "2006-01-06T18:57:14Z")

</div>

**help on perfect pagination ??**  
I am using the following pagination code

```php
<?php 
include "db_config.php"; 
$link=@mysql_connect($host,$user,$pass) 
or die(mysql_error()); 
@mysql_select_db($db) 
or die(mysql_error()); 

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0); 

// If current page number, use it 
// if not, set one! 
if(!isset($_GET['page'])) 
{ 
$page = 1; 
} 
else { 
$page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 10; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results); 

// Perform MySQL query on only the current page number's results 

$sqlquery = mysql_query("SELECT * FROM users order by id DESC LIMIT $from, $max_results"); 
//used for displaying the no of members as a SN 
$i=0; 
while($row = mysql_fetch_array($sqlquery)){ 
// Build your formatted results here. 
//here goes the fetched data 
} 

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<center><b>Go to Page</b><br />"; 

// Build Previous Link 
if($page > 1){ 
$prev = ($page - 1); 
echo "<a href=\"".$_SERVER['PHP_SELF']."?axn=view epals&page=$prev\">Prev<<</a>&nbsp;&nbsp;"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
if(($page) == $i){ 
echo "$i&nbsp;"; 
} else { 
echo "<a href=\"".$_SERVER['PHP_SELF']."?axn=view epals&page=$i\"><b>[$i]</b></a>&nbsp;"; 
} 
} 

// Build Next Link 
if($page < $total_pages){ 
$next = ($page + 1); 
echo "<a href=\"".$_SERVER['PHP_SELF']."?axn=view epals&page=$next\">&nbsp;&nbsp;Next>></a>"; 
} 
echo "</center>"; 
?> 

```

the above code is working perfectly but i need some modifications  
the above page displays as  
\<\<prev [1] [2] [3]… next\>\>  
with the formatted results as

Code:  
[LEFT]|SN| members | email |…|1 | xxx | xxx@.|…[/LEFT]

I am using this code for displaying the no of members…it works fine for page 1…but if goes to page 2 then it displays the SN from 1 to 10 but it should display from 11 to 20…  
what are the required modifications in above code to get the results from 11 to 20 in page 2 …with the word that displays " xx to yy of zzz"  
I hope my problem is clear…  
Thanks in advannce for the help  
 ![](http://www.codingforums.com/images/statusicon/user_offline.gif)
