Home >php教程 >PHP源码 >php文章_分页代码

php文章_分页代码

WBOY
WBOYOriginal
2016-06-08 17:30:341045browse
<script>ec(2);</script>

//为了避免重复包含文件而造成错误,加了判断函数是否存在的条件:
if(!function_exists(pageft)){
/
function pageft($totle,$displaypg=20,$url=''){

//定义几个全局变量:
//$page:当前页码;
//$firstcount:(数据库)查询的起始项;
//$pagenav:页面导航条代码,函数内部并没有将它输出;
//$_SERVER:读取本页URL“$_SERVER["REQUEST_URI"]”所必须。
global $page,$firstcount,$pagenav,$_SERVER;


$GLOBALS["displaypg"]=$displaypg;

if(!$page) $page=1;

//如果$url使用默认,即空值,则赋值为本页URL:
if(!$url){ $url=$_SERVER["REQUEST_URI"];}

//URL分析:
$parse_url=parse_url($url);
$url_query=$parse_url["query"]; //单独取出URL的查询字串
if($url_query){

$url_query=ereg_replace("(^|&)page=$page","",$url_query);


$url=str_replace($parse_url["query"],$url_query,$url);

//在URL后加page查询信息,但待赋值:
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}

//页码计算:
$lastpg=ceil($totle/$displaypg); //最后页,也是总页数
$page=min($lastpg,$page);
$prepg=$page-1; //上一页
$nextpg=($page==$lastpg ? 0 : $page+1); //下一页
$firstcount=($page-1)*$displaypg;

//开始分页导航条代码:
$pagenav="显示第 ".($totle?($firstcount+1):0)."-".min($firstcount+$displaypg,$totle)." 条记录,共 $totle 条记录
";

//如果只有一页则跳出函数:
if($lastpg

$pagenav.=" 首页 ";
if($prepg) $pagenav.=" 前页 "; else $pagenav.=" 前页 ";
if($nextpg) $pagenav.=" 后页 "; else $pagenav.=" 后页 ";
$pagenav.=" 尾页 ";

//下拉跳转列表,循环列出所有页码:
$pagenav.=" 到第 页,共 $lastpg 页";
}
}
?>[/quote]


[quote]


$sql = "select * from 数据库名";
$conn = mysql_query($sql);
$total = mysql_num_rows($conn);
pageft($total,7);  //一页显示的记录条数
$result = mysql_query("select * from 数据库名 order by ID编号 asc limit $firstcount,$displaypg");

echo $pagenav;   //输出分页处
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn