Return to Snippet

Revision: 31633
at September 28, 2010 21:01 by mattlowden


Updated Code
function page_list($link, $page, $per_page, $total_rows, $options = array()){

	$link = urldecode($link);

	$default_options = array(
		'paging_range' => 2,
		'first_last_link' => true,
		'first_character' => '<em>&laquo;</em> First',
		'last_character' => 'Last <em>&raquo;</em>',
	);

	$options = array_merge_replace($default_options, $options);

	$total_pages = ceil($total_rows / $per_page);
	$record_start = $page > 1 ? ($per_page * ($page-1)) : 0;
	$record_end = ($record_start + $per_page) > $total_rows ? $total_rows : ($record_start + $per_page);

	$page_list = array();

	if($total_pages > 1){

		$first_display_page = $page - $default_options['paging_range'];
		$first_display_page = $first_display_page < 1 ? 1 : $first_display_page;
		$last_display_page = $page + $default_options['paging_range'];
		$last_display_page = $last_display_page > $total_pages ? $total_pages : $last_display_page;

		for($p = $first_display_page; $p <= $last_display_page; $p++){
			$page_data = array(
				'page' => $p,
				'text' => $p,
				'link' => ''
			);


			if($options['first_last_link'] === true && $first_display_page === $p && $first_display_page > 1){
				$page_data['text'] = $default_options['first_character'];
				$page_data['page'] = 1;
			}elseif($options['first_last_link'] === true && $last_display_page === $p && $total_pages > $p){
				$page_data['text'] = $default_options['last_character'];
				$page_data['page'] = $total_pages;
			}

			$page_data['link'] = str_replace('{page}', $page_data['page'], $link);

			$page_list[] = $page_data;

		}
		

	}

	$pages = '<p class="text">Page '.number_format($page).' of '.number_format($total_pages).'</p>';

	if(count($page_list) > 0){
		$pages .= '<ul class="list">';
		foreach($page_list as $single_page){
			$pages .= '<li class="'.($single_page['page'] == $page ? ' selected' : false ).'"><span><a href="'.$single_page['link'].'">'.$single_page['text'].'</a></span></li>';
		}
		$pages .= '</ul>';
	}
		

	return $pages;

}

Revision: 31632
at September 10, 2010 00:08 by mattlowden


Updated Code
function page_list($link, $page, $per_page, $total_rows, $rel=null){
	$total = ceil($total_rows/$per_page);
	$record_start = $page > 1 ? ($per_page * ($page-1)) : 0;
	$record_end = $record_start+$per_page > $total_rows ? $total_rows : $record_start+$per_page;
	$pages = '<p class="text">Page '.$page.' of '.$total.'</p>';
	
	$pages .= '<ul class="list">';
	if($total > 1){
		for($p = 0; $p < $total; $p++){
			if((($p < ($page + 3)) && ($p > ($page - 5))) || ($p == 0) || ($p == $total-1)){
				$pages .= '<li class="'.($p+1 == $page ? ' selected' : false ).'"><span><a'.($rel?(' rel="'.$rel.'"'):null).' href="'.str_replace('{page}', ($p+1), $link).'">'.($p == $total-1&&$page<$total-3?'... ':null).($p+1).($p == 0 && ($page > 4)?' ...':null).'</a></span></li>';
			}
		}
	}

	$pages .= '</ul>';
	return $pages;
}

Revision: 31631
at September 9, 2010 22:09 by mattlowden


Updated Code
function page_list($link, $page, $per_page, $total_rows, $rel=null){
	$total = ceil($total_rows/$per_page);
	$record_start = $page > 1 ? ($per_page * ($page-1)) : 0;
	$record_end = $record_start+$per_page > $total_rows ? $total_rows : $record_start+$per_page;
	$pages = '<p class="text">Page '.$page.' '.$total.'</p>';
	
	$pages .= '<ul class="list">';
	if($total > 1){
		for($p = 0; $p < $total; $p++){
			if((($p < ($page + 3)) && ($p > ($page - 5))) || ($p == 0) || ($p == $total-1)){
				$pages .= '<li class="'.($p+1 == $page ? ' selected' : false ).'"><span><a'.($rel?(' rel="'.$rel.'"'):null).' href="'.str_replace('{page}', ($p+1), $link).'">'.($p == $total-1&&$page<$total-3?'... ':null).($p+1).($p == 0 && ($page > 4)?' ...':null).'</a></span></li>';
			}
		}
	}

	$pages .= '</ul>';
	return $pages;
}

Revision: 31630
at September 9, 2010 22:00 by mattlowden


Initial Code
function page_list($link, $page, $per_page, $total_rows, $rel=null){
	$total = ceil($total_rows/$per_page);
	$record_start = $page > 1 ? ($per_page * ($page-1)) : 0;
	$record_end = $record_start+$per_page > $total_rows ? $total_rows : $record_start+$per_page;
	$pages = '<ul class="page-list clear-fix">';
	$pages .= '<li class="first">Viewing records <strong>'.($record_start+1).'</strong> - <strong>'.$record_end.'</strong> of <strong>'.$total_rows.'</strong></li>';
	
	if($total > 1){
		for($p = 0; $p < $total; $p++){
			if((($p < ($page + 3)) && ($p > ($page - 5))) || ($p == 0) || ($p == $total-1)){
				$pages .= '<li class="page'.($p+1 == $page ? ' selected' : false ).'"><span><a'.($rel?(' rel="'.$rel.'"'):null).' href="'.str_replace('{page}', ($p+1), $link).'">'.($p == $total-1&&$page<$total-3?'... ':null).($p+1).($p == 0 && ($page > 4)?' ...':null).'</a></span></li>';
			}
		}
	}
	$pages .= '</ul>';
	return $pages;
}

Initial URL

                                

Initial Description

                                

Initial Title
page_list (With HTML output)

Initial Tags

                                

Initial Language
PHP