Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Pagination

Status
Not open for further replies.

benrob82

Programmer
Jul 28, 2005
116
0
0
GB
Hi I have setup a nice little paging system to allow the page numbers to be displayed.

The problem is I want to be able to show 10 pages at a time i.e. page 1.....10 then when page 2 is clicked it shows 2.....11 etc etc, does anyone know how to do this or is there a simple way I could add this to my code below.

Code:
$page = (!isset($_GET['page']))? 1 : $_GET['page']; 
$prev = ($page - 1); 
$next = ($page + 1); 

/* Max results per page */ 
$max_results = 10; 

/* Calculate the offset */ 
$from = (($page * $max_results) - $max_results); 
$getresults = mysql_query("select `id`,`title`,`introtext`,`fulltext`,`created` from `mos_content` where `sectionid` = '2' and `state` ='1'"); 
$total_results = mysql_num_rows($getresults); 
$total_pages = ceil($total_results / $max_results); 
$pagination = ''; 


$news = mysql_query("select * from table where whatever LIMIT $from, $max_results"); 
while ($i = mysql_fetch_row($news)) 
{
		echo "Whatever the results are";
}

/* Create a PREV link if there is one */ 
if($page > 1) 
{ 
	$pagination .= '<a href="news.php?page='.$prev.'">Previous</a> '; 
} 

/* Loop through the total pages */ 
for($i = 1; $i <= $total_pages; $i++) 
{ 
	if(($page) == $i) 
{ 
	$pagination .= $i.'&nbsp;&nbsp;'; 
} 
else 
{ 
	$pagination .= '<a href="news.php?page='.$i.'">'.$i.'</a>&nbsp;&nbsp;'; 
} 
} 

/* Print NEXT link if there is one */
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top