holy shit

寺夺喜从天降

php分页函数一

代码:

/**
 * 分页函数
 * @param int $page_count
 * @param int $page_index
 * @param string $url
 * @return string
 */
function pagelist($page_count,$page_index,$url=''){
	$output='<div class="pagelist cle">';

	if($page_index==1){
		$output.='<span>首页</span><span>上一页</span>';
	}else {
		$output.='<a href="'.$url.'?page=1">首页</a><a href="'.$url.'?page='.($page_index-1).'">上一页</a>';
	}
	
	if($page_index<6 || $page_count<10){
		for($i=1;$i<10;$i++){
			if($i!=$page_index){
				$output.='<a href="'.$url.'?page='.$i.'">'.$i.'</a>';
			}else{
				$output.='<a href="'.$url.'?page='.$i.'" class="current">'.$i.'</a>';
			}
			if($i>=$page_count){
				break;
			}
		}
	}elseif ($page_index>5 && $page_index<$page_count-3){
		for($i=$page_index-4;$i<$page_index+5;$i++){
			if($i!=$page_index){
				$output.='<a href="'.$url.'?page='.$i.'">'.$i.'</a>';
			}else {
				$output.='<a href="'.$url.'?page='.$i.'" class="current">'.$i.'</a>';
			}
			if($i>=$page_count){
				break;
			}
		}
	}elseif ($page_index>$page_count-5){
		for($i=$page_count-8;$i<$page_count+1;$i++){
			if($i>1){
				if($i!=$page_index){
					$output.='<a href="'.$url.'?page='.$i.'">'.$i.'</a>';
				}else {
					$output.='<a href="'.$url.'?page='.$i.'" class="current">'.$i.'</a>';
				}
			}
		}
	}
	if($page_index<$page_count){
		$output.='<a href="'.$url.'?page='.($page_index+1).'">下一页</a><a href="'.$url.'?page='.$page_count.'">末页</a>';
	}else {
		$output.='<span>下一页</span><span>末页</span>';
	}
	$output.='</div>';
	return $output;
}

样式:

.pagelist {
	padding-left: 200px;
}
.pagelist span {
	display: block;
	border: 1px solid #999999;
	margin-right: 6px;
	color: #999999;
	padding-top: 0px;
	padding-right: 6px;
	padding-bottom: 0px;
	padding-left: 6px;
	float: left;
}
.pagelist a {
	display: block;
	border: 1px solid #339900;
	margin-right: 6px;
	text-decoration: none;
	color: #339900;
	padding-top: 0px;
	padding-right: 6px;
	padding-bottom: 0px;
	padding-left: 6px;
	float: left;
}
.pagelist .current {
	font-weight: bold;
	color: #FFFFFF;
	background-color: #339900;
}
.pagelist a:hover {
	font-weight: bold;
	color: #FFFFFF;
	background-color: #339900;
	text-decoration: none;
}
posted @ 2011-03-24 23:07  潜水鱼  阅读(167)  评论(0编辑  收藏  举报

holy shit on foot