Recommend this page to a friend! |
MSSQL Pagination | > | All threads | > | Iterating through numbers | > | (Un) Subscribe thread alerts |
|
Steve Barbera - 2008-09-03 16:53:11
A while back I asked about how to display the numbers in a format so that you don't see all of the Page Numbers but only a 3 before and 3 after the current number Example:
First | Previous | 1 | 2 | 3 | Current | 4 | 5 | 6 | Next | Last It might not be the most efficient code in the world but it works pretty good. function show_navigation($displayname = "Page"){ echo "<div class='HFPagination'>"; $var = $this->get_var; $total_row = $this->get_total_rows(); $total_page = $this->get_num_pages() * $this->num_per_page; $total_max = ($total_page - $total_row); $current_page = $this->set_page() +1; $previous_page = $current_page - 2; $last_page = $this->num_of_pages - 1; //For the first page if($current_page == 1){ for($PageCount = 0; $PageCount <= 4; $PageCount++){ if($PageCount == $current_page - 1){ echo "<b>".($PageCount+1)."</b>"; }else{ echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$PageCount.$this->rebuild_qs($var)."\">".($PageCount+1)."</a>"; } } echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$current_page.$this->rebuild_qs($var)."\"> Next ></a>"; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$last_page.$this->rebuild_qs($var)."\">Last Page >></a>"; } //For the current Page if($current_page > 1 && $current_page < $this->num_of_pages){ echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=0".$this->rebuild_qs($var)."\"><< First Page</a>"; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$previous_page.$this->rebuild_qs($var)."\">< Previous</a>"; for($PageCount = $current_page - 2; $PageCount <= $current_page; $PageCount++){ if($PageCount > 1){ $previous_page = $PageCount - 2; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$previous_page.$this->rebuild_qs($var)."\">".($PageCount - 1)."</a>"; } } echo "<b>".($current_page)."</b>"; for($PageCount = $current_page; $PageCount <= $current_page + 2; $PageCount++){ if($PageCount <= $last_page){ echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$PageCount.$this->rebuild_qs($var)."\">".($PageCount+1)."</a>"; } } echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$current_page.$this->rebuild_qs($var)."\">Next ></a>"; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$last_page.$this->rebuild_qs($var)."\"> Last Page >></a>"; } //For the last page if($current_page == $this->num_of_pages){ echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=0".$this->rebuild_qs($var)."\">First Page</a>"; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$previous_page.$this->rebuild_qs($var)."\">< Previous</a>"; for($PageCount = $this->num_of_pages - 4; $PageCount <= $this->num_of_pages; $PageCount++){ $previous_page = $PageCount - 2; echo "<a href=\"".$_SERVER['PHP_SELF']."?".$this->get_var."=".$previous_page.$this->rebuild_qs($var)."\">".($PageCount - 1)."</a>"; } echo "<b>".$this->num_of_pages."</b>"; } echo "</div>"; } Cheers! Steve |
info at phpclasses dot org
.