xyn Posted July 23, 2006 Share Posted July 23, 2006 Hey,I basically have a news system which I wanted to show 6 articles Per pageand have page numbers at the bottom like:[ 1 | 2 | 3 | 4 | 5 | >> ]And when you get to page 2+ it adds "<<" previous. and obviouslywhen it's on the last page you can't go ">>" next.Does anyone have any ideas how i can achieve this? Quote Link to comment https://forums.phpfreaks.com/topic/15379-php-pages-numbers/ Share on other sites More sharing options...
AndyB Posted July 23, 2006 Share Posted July 23, 2006 Check the pagination tutorial here -> http://www.phpfreaks.com/tutorials/43/0.php Quote Link to comment https://forums.phpfreaks.com/topic/15379-php-pages-numbers/#findComment-62345 Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 Here's an example that uses grouping of pages, useful if you have a lot pages:[code]$page = !isset($_GET['page'])?1:$_GET['page'];printNavLinks(800, 6, 10, $page);function printNavLinks($totalItems, $maxitems, $groupsize, $currpage){ //Get number of pages: $pages = ceil($totalItems / $maxitems); //Divide the pages into groups: $groupnr = 0; for($page=1; $page<$pages; $page++) { //If page is dividable by the groupsize, new group. if($page % $groupsize == 0){ $groupnr++; } $groupArr[$page] = $groupnr; } //Display 'previous page link': if($currpage>1){ echo '<a href=test.php?page='.($currpage-1).'>< Previous </a>'; } $groupToDisplay = $groupArr[$currpage]; //Display pages in this group: foreach($groupArr as $page=>$groupnr) { if($groupnr == $groupToDisplay) { if($page == $currpage){ echo '<strong><a href=test.php?page='.$page.'> ['.$page.'] </a></strong>'; } else { echo '<a href=test.php?page='.$page.'> ['.$page.'] </a>'; } } } //Display 'next page link': if(isset($groupArr[$currpage+1])){ echo '<a href=test.php?page='.($currpage+1).'> Next ></a>'; }}?>[/code]To fetch from mysql use:[code]'SELECT * FROM table LIMIT '.($currpage-1)*$maxitems.', '.$maxitems[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15379-php-pages-numbers/#findComment-62354 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.