Home >php教程 >PHP源码 >php mysql网页分页代码

php mysql网页分页代码

WBOY
WBOYOriginal
2016-06-08 17:26:541309browse

在php+mysql数据库的分页代码中比以前的asp,asp.net相对来就容易很多,因为mysql支持limit,0,N这样就可以轻松快速的获取要读取的记录,好下面来看实例

<script>ec(2);</script>
 代码如下 复制代码

function getpage ($talbe,$choose,$url){
 global $page,$db,$sortname;
 $query=$db->query("select * from $talbe $choose");
 $total=$db->num_rows($query);
 $totalpage=ceil($total/25);
 $nextpage=$page+1;
 $uppage=$page-1;
 if($nextpage>$totalpage)$nextpage=$totalpage;
 if($uppage  $showpage="共有$total条记录,共$totalpage页,当前为第$page
                          上一页下一页◇";
    return $showpage;
}
function reto($msg,$url=''){
 global $comeurl;
 if(!$url)$url=$comeurl;
 return "


                     

                       

                     

                   

                         
                       
";
}

通过上页的代码我们可以看出php分页原创很简单,只要get[page]页面,当前页,然后再用$page*$pagesize以开始,后以$pagesize为结束就OK了。mysql语句为 $sql ="Select * from t limit $page*$pagesize,$pagesize";

本站原创教程,转载注明来源www.111cn.net

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