myfan Posted April 5, 2007 Share Posted April 5, 2007 i used parts of the pagination script found on phpfreaks but have modified it abit. So now my only issue i have is i need it to after giving me how many pages is to only display like 5 of the pages but on an upward route like < 1 2 3 4 5 > what i want is lets say i want to limit the amount of pages in the pagination so that when i click 5 it shows me < 4 5 6 7 8 > here is my code $begin = $numofpages - $numofpages; while($begin < 1) $begin++; $end = $begin + 4; while($end > $numofpages) $end--; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"index.php?page=$i\">$i</a> "); } } if(($totalrows % $per_page) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"index.php?page=$i\">$i</a> "); } } } Quote Link to comment Share on other sites More sharing options...
$cripts Posted April 5, 2007 Share Posted April 5, 2007 you can use this script i wrote a simple little pagination but it uses a range so u can put a range of 4 and it go 1 2 [ 3 ] 4 5 function pages($url,$total_items,$per_page,$range,$current_page) { // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_items / $per_page); $range = ceil($range / 2); if($current_page != 1) { $return = '[<a href="'.$url.'p=1" title="Go to page 1 of '.$total_pages.'"> « </a>]'; } if($current_page > 1){ $prev = ($current_page - 1); $return .= '<a href="'.$url.'p='.$prev.'" title="Go to page '.$prev.' of '.$total_pages.'"> « </a>'; } // Build Backward Links for($i = 1; $i <= $range; $i++){ $p = $current_page-$i; if($p > 0) { $back .= $p.','; } } $back_rev = strrev($back); $back_rev = explode(',',$back_rev); foreach($back_rev as $rev) { $rev = strrev($rev); $return .= ' <a href="'.$url.'p='.$rev.'" title="Go to page '.$rev.' of '.$total_pages.'">'.$rev.'</a> '; } $return .= ' [ <b>'.$current_page.'</b> ] '; for($i = 1; $i <= $range; $i++){ $p = $current_page+$i; if($p <= $total_pages) { $return .= '<a href="'.$url.'p='.$p.'" title="Go to page '.$p.' of '.$total_pages.'">'.$p.'</a> '; } } // Build Next Link if($current_page < $total_pages && $total_pages != '0') { $next = $current_page + 1; $return .= '<a href="'.$url.'p='.$next.'" title="Go to page '.$next.' of '.$total_pages.'"> » </a>'; } if($current_page != $total_pages && $total_pages != '0') { $return .= '[ <a href="'.$url.'p='.$total_pages.'" title="Go to page '.$total_pages.' of '.$total_pages.'"> » </a> ]'; } return $return; } Quote Link to comment 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.