PHP分页导航函数

这个函数是去年写的,之前在独立博客上发布的。
	function show($config=array()){
		
		// 初始化
		
		if(!isset($config['total'])) return FALSE;
		if(!isset($config['pagesize'])) $config['pagesize']=10;
		if(!isset($config['page'])) $config['page']=1;
		if(!isset($config['base'])) $config['base']='?&page=';
		if(!isset($config['suffix'])) $config['suffix']='';
		
		if(!isset($config['first_text'])) $config['first_text']='首页';
		if(!isset($config['first_open'])) $config['first_open']='';
		if(!isset($config['first_close'])) $config['first_close']='';
		
		if(!isset($config['last_text'])) $config['last_text']='尾页';
		if(!isset($config['last_open'])) $config['last_open']='';
		if(!isset($config['last_close'])) $config['last_close']='';
		
		if(!isset($config['next_text'])) $config['next_text']='下一页';
		if(!isset($config['next_open'])) $config['next_open']='';
		if(!isset($config['next_close'])) $config['next_close']='';
		
		if(!isset($config['prev_text'])) $config['prev_text']='上一页';
		if(!isset($config['prev_open'])) $config['prev_open']='';
		if(!isset($config['prev_close'])) $config['prev_close']='';
		
		if(!isset($config['num_open'])) $config['num_open']='';
		if(!isset($config['num_close'])) $config['num_close']='';
		
		if(!isset($config['c_open'])) $config['c_open']='';
		if(!isset($config['c_close'])) $config['c_close']='';
		
		if(!isset($config['display_num'])) $config['display_num']=TRUE;
		if(!isset($config['num_list'])) $config['num_list']=4;
				
		// 计算
		$config['page']=ceil($config['page']);
		$pages = ceil ( $config['total'] / $config['pagesize'] );
		$offset= ($config['page']-1)*$config['pagesize'];
		
		
		// 判断
		if(!is_numeric($config['page'])) $config['page']=1;
		if($config['page']>$pages) return FALSE;
		if($config['page']<1) return FALSE;
		
		// 生成
		$tmp='';
		
		// 首页 上一页
		if ($config['page']-1 < 1) {
			$tmp .= $config['first_open'].$config['first_text'].$config['first_close'].' ';
			$tmp .= $config['prev_open'].$config['prev_text'].$config['prev_close'].' ';
		} else {
			$tmp .= $config['first_open'].''.$config['first_text'].''.$config['first_close'].' ';
			$tmp .= $config['prev_open'].''.$config['prev_text'].''.$config['prev_close'].' ';
		}
		
		// 中间数字
		if($config['display_num']){
		$st=$config['page']-$config['num_list'];
		$et=$config['page']+$config['num_list'];
		
		if($st<1)$st=1;
		if($et>$pages)$et=$pages;
		
		for($i=$st;$i<=$et;$i++){
			if($i==$config['page']){
				$tmp.=	$config['num_open'].$i.$config['num_close'].' ';
			}
			else
			{
				$tmp.=	$config['c_open'].''.$i.''.$config['c_close'].' ';
			}
		}
		
		}
		// 尾页 下一页
		if ($config['page'] >= $pages) {
			$tmp .= $config['next_open'].$config['next_text'].$config['next_close'].' ';
			$tmp .= $config['last_open'].$config['last_text'].$config['last_close'].' ';
		} else {
			$tmp .= $config['next_open'].''.$config['next_text'].''.$config['next_close'].' ';
			$tmp .= $config['last_open'].''.$config['last_text'].''.$config['last_close'].' ';
		}
		
		
		return $tmp;
	}

你可能感兴趣的:(PHP分页导航函数)