/***************************************************
函数功能: 翻页
参数说明: $page_url, $count, $offset, $class;
返回值: echo
***************************************************/
function page_nav($page_url,$count,$offset=10,$class='pagenav')
{
global $page;
$num_pages=sprintf("%d",($count-1)/$offset);
if($num_pages>0)
{
$num_pages+=1;
$first="<span class='$class'>".'<< 首页'.'</span>';
$previous="<span class='$class'>".'上一页'.'</span>';
$next="<span class='$class'>".'下一页'.'</span>';
$end="<span class='$class'>".'末页 >>'.'</span>';
if($page>1)$first="<a href='$page_url' class='$class'>".'<< 首页'."</a>";
if($page>1)$previous="<a href='$page_url&page=".($page-1)."' class='$class'>".'上一页'."</a>";
if($page<$num_pages)$next="<a href='$page_url&page=".($page+1)."' class='$class'>".'下一页'."</a>";
if($page<$num_pages)$end="<a href='$page_url&page=".$num_pages."' class='$class'>".'末页 >>'."</a>";
$page_links='';
$half=2;
if($num_pages<=(2*$half+1) || $num_pages>(2*$half+1) && $page<=$half+1) $left=1;
else if($num_pages>(2*$half+1) && $num_pages-$page<=$half) $left=$num_pages-2*$half;
else $left=$page-$half;
if($num_pages<=(2*$half+1) || $num_pages>(2*$half+1) && $num_pages-$page<=$half) $right=$num_pages;
else if($num_pages>(2*$half+1) &&$page<=$half+1) $right=(2*$half+1);
else $right=$page+$half;
for($pn=$left ; $pn<=$right ; $pn ++)
{
if($pn == $page)$page_links.="<span class='$class'>$pn</span>";
else $page_links.=" <a href='$page_url&page=".$pn."' class='$class'>$pn</a> ";
}
echo "共<font color=red>$num_pages</font>页<font color=red>$count</font>条 <center> $first $previous $page_links $next $end </center>";
for($pn=1; $pn<=$num_pages; $pn ++)
{
if($pn == $page)$page_links.="<span class='$class'>$pn</span>";
else $page_links.=" <a href='$page_url&page=".$pn."' class='$class'>$pn</a> ";
}
echo "<center> $first $previous $page_links $next $end </center>";
}
}
posted on 2005-07-18 17:21
楚客 阅读(380)
评论(0) 编辑 收藏 所属分类:
PHP