快活林资源网 Design By www.csstdc.com

复制代码 代码如下:
<?php
function genpage(&$sql,$page_size=10)
{
global $pages,$sums,$eachpage,$page; //总页数,总记录,每页数,当前页
$page = $_GET["page"];
if($page ==0)$page =1;
$eachpage = $page_size;
$pagesql = strstr($sql," from ");
$pagesql = "select count(*) as ids ".$pagesql;
$conn = mysql_query($pagesql) or die(mysql_error());
if($rs = mysql_fetch_array($conn))$sums = $rs[0];
$pages=ceil($sums/$eachpage);
if($pages==0)$pages=1;
$startpos = ($page-1)*$eachpage;
$sql .=" limit $startpos,$eachpage ";
}

//显示分页
function showpage()
{
global $pages,$sums,$eachpage,$page; //总页数,总记录,每页数,当前页,其它参数
$link=$_SERVER['PHP_SELF'];
echo "记录".$sums.":".$eachpage." ";
echo "页数".$page."/".$pages." ";
$p_head=$page-5;
if($p_head<=0)$p_head=1; //页码循环开始数 前5个
$p_end=$page+5;
if($p_end>$pages)$p_end=$pages; //页码循环结束数 后5个
echo "[<a href=$link?page=1>首页</a>] ";
for($i=$p_head;$i<=$p_end;$i++)
{
if($i!=$page)
echo "<a href=$link?page=$i>[$i]</a> ";
else
echo "<b><strike>[$i]</strike></b> ";
}
echo " [<a href=$link?page=$pages>末页</a>]";
}
?>

快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com