Return to Snippet

Revision: 29542
at July 31, 2010 08:13 by brainwaves


Initial Code
//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
	if($type=='database') $r=mysql_num_rows(mysql_query($query));
	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{
		$n=ceil($r/$per_page); //total number of pages
		$previouspage=$thispage-1;
		$nextpage=$thispage+1;
		$maxCurrentPage = 7;
	
	 	if($previouspage<=$n && $previouspage>=1){
	 		$links.='<a href="'.$url.'1" title="First Page" class="'.$class.'">&laquo; First</a> <a href="'.$url.$previouspage.'" title="Previous Page" class="'.$class.'">&laquo; 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 &raquo;</a> <a href="'.$url.$n.'" title="Last Page" class="'.$class.'">Last &raquo;</a>';
		}
		
	}
	
	$links.='</div>';		
	return $links;
}

Initial URL

                                

Initial Description

                                

Initial Title
Pagination function

Initial Tags
textmate, navigation

Initial Language
PHP