/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//displays the pagination function pagination($total_or_query, $thispage='', $url='', $type='database', $class='', $per_page_overwrite=''){ global $site; $per_page = $site['perPage']; if($per_page_overwrite) $per_page=$per_page_overwrite; $links='<div class="pagination">'; //returns the no of entries in table else $r=$total; if($type=='database' && !$r){ trigger_error('Pagination Database Error<br /><small class="verysmall">Technical Message: '.mysql_error().'</small>', E_USER_ERROR); }elseif($type!='database' && !$r){ return false; }else{ $previouspage=$thispage-1; $nextpage=$thispage+1; $maxCurrentPage = 7; if($previouspage<=$n && $previouspage>=1){ $links.='<a href="'.$url.'1" title="First Page" class="'.$class.'">« First</a> <a href="'.$url.$previouspage.'" title="Previous Page" class="'.$class.'">« Previous</a>'; } if( $thispage <= $n ){ if( $thispage <= 3 ){ $max = ( $n > $maxCurrentPage ) ? $maxCurrentPage : $n; for($i = 1; $i<=$max; $i++){ $links .= ( $i == $thispage ) ? '<a href="'.$url.$i.'" class="number current '.$class.'" title="Page '.$i.'">'.$i.'</a>' : '<a href="'.$url.$i.'" class="number '.$class.'" title="Page '.$i.'">'.$i.'</a>'; } }else{ for($i = ($thispage-3); $i<=($thispage+3); $i++){ if( $i <= $n ){ $links .= ( $i == $thispage ) ? '<a href="'.$url.$i.'" class="number current '.$class.'" title="Page '.$i.'">'.$i.'</a>' : '<a href="'.$url.$i.'" class="number '.$class.'" title="Page '.$i.'">'.$i.'</a>'; } } } } if($nextpage<=$n){ $links.='<a href="'.$url.$nextpage.'" title="Next Page" class="'.$class.'">Next »</a> <a href="'.$url.$n.'" title="Last Page" class="'.$class.'">Last »</a>'; } } $links.='</div>'; return $links; }