Home > php教程 > PHP源码 > php入门级别的分页函数

php入门级别的分页函数

WBOY
Release: 2016-06-08 17:26:19
Original
1169 people have browsed it

这是一款简单实用的php分页代码,如果你是php初学者来看看这款实用的分页代码吧。

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

function page($sql,$pagesize=10,$class=""){
 
 if(!is_string($sql)){ return 0;exit;}
 $result=mysql教程_query($sql);
 if(!$result){return 0;exit;}
 if(!$recordnum=mysql_num_rows($result)){return 0;exit;}
 $totalpage=ceil($recordnum/$pagesize);
 $page=(int)$_get['page'];
 if($page  if($page>=$totalpage) $page=$totalpage;
 $recordno=($page-1)*$pagesize;
 $sql.=" limit $recordno,$pagesize";
 $result=mysql_query($sql);
 $url=$_server["php_self"];

 if($page==1)$str= "首页|上页";
 else $str.="首页上页";
 if($page==$totalpage) $str.=  "|下页|末页";
 else  $str.="|下页末页";
 $str.=" 当前第 $page 页 共 $totalpage 页";
 return array($result,$str);
}
//调用方法

$sql="select * from images order by imid";
$result=page($sql,16);

/*
简单的原是就是根据传过来的传到数据库教程中去读取相对应多的记录,这样就实现的分页。
*/

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template