pagination script shows only 10 pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phpmash
Forum Newbie
Posts: 24
Joined: Mon Oct 31, 2005 6:41 am
Location: Kerala,India
Contact:

pagination script shows only 10 pages

Post by phpmash »

hello php guys,
Presently i hvae the pagination script which shows the pages,next, previous links.
but in some cases i have around 70 pages , so it is not attractive to show all these in a page.
So i would like to get a script which shows only 10 pages,prevoius 10,previous,next 10,next links only.

Thanks

:roll:
phpmash
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Just do something like this:

UNTESTED:

Code: Select all

<?php 

$currentpage = 60;
$nextpage = ($currentpage+1);
$previouspage = ($currentpage-1);
$minpage = ($currentpage-11);
$maxpage = ($currentpage+11);
print('<a href="page.php?'. $previouspage .'">Previous</a>');
for($i=$minpage; $i<=$minpage; $i++){
       $minpage = ($minpage+1)
       print('<a href="page.php?'. $minpage .'">' . $minpage . '</a>');
}
for($i=$maxpage; $i<=$maxpagee; $i++){
       $maxpage = ($maxpage+1)
       print('<a href="page.php?'. $maxpage .'">' . $maxpage . '</a>');
}
print('<a href="page.php?'. $nextpage .'">Next</a>');

?>
Post Reply