Jun
9
PHP分页函数
tommyhu , 14:59 , PHP , Comments(0) , Trackbacks(0) , Reads(8921) , Via Original
Large | Medium | Small


PHP分页函数
<?
function page ( $totalPage , $currentPage,$url ,$halfPer=5)
{
$total=$totalPage-1;
$re="<td><a href=\"$url\" onclick=\"page=prompt('共{$totalPage}页\\n自定义跳转到第几页:',''[separator]);if(page>0&&page<$total)location.href=this.href+'='+(page-1);return false\">跳转</a></td>\n";
$re .= ( $currentPage > 0 )
? "<td><a href=\"$url=0\">首页</a></td>\n<td><a href=\"$url=".($currentPage-1)."\">上一页</a></td>\n"
: "<td>首页</td>\n<td>上一页</td>\n";
for ( $i = $currentPage - $halfPer,$i > 0 || $i = 0 , $j = $currentPage + $halfPer, $j < $totalPage || $j = $totalPage;$i < $j ;$i++ )
{
$re .= $i == $currentPage
? "<td><b class=currentPage>[" . ( $i + 1 ) . "]</b></td>\n"
: "<td><a href=\"$url=$i\">" . ( $i + 1 ) . "</a></td>\n";
}
$re .= ( $currentPage < $total )
? "<td><a href=\"$url=" . ( $currentPage + 1 ) . "\">下一页</a></td>\n<td><a href=\"$url=" . ( $total )."\">尾页</a>\n</td>"
: "<td>下一页</td>\n<td>尾页</td>\n";
$re="<table style=text-align:center><tr>$re</tr></table>";
return $re;
}
?>
函数描述及例子
<?
$totalPage = 100 ; //总分页数量
$currentPage = @$_GET['page']+0; //当前页码
$url = "?page"; //分而链接
$halfPer = 10; //二分之一的每页的信息数
$imagePath ="images"; //分页图片目录
$pageHtml = page ( $totalPage , $currentPage,$url ,$halfPer,$imagePath);//调用分页函数
echo $pageHtml ;?>