search
Homephp教程PHP源码php入门级别的分页函数

这是一款简单实用的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);

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function