>  기사  >  백엔드 개발  >  简单实用php mysql分页代码_PHP教程

简单实用php mysql分页代码_PHP教程

WBOY
WBOY원래의
2016-07-13 17:05:10808검색

简单实用php mysql分页代码

简单实用php教程 mysql教程分页代码
$qh=mysql_query("select count(*) as rcnt from table where your_condition_here order by whatever");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0

if (empty($offset))
{
$offset=0;
}

//查询结果(这里是每页20条,但你自己完全可以改变它)
$result=mysql_query("select id,name,phone from table where your_condition_here order by whatever limit $offset, 20");

//显示返回的20条记录
while ($data=mysql_fetch_array($result))
{

//换成你用于显示返回记录的代码

}

//下一步,要写出到其它页面的链接
if(!$offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-20;
print "前一页 n";
}

//计算总共需要的页数
$pages=ceil($nr/20); //$pages变量现在包含所需的页数

for ($i=1; $i {
$newoffset=20*$i;
print "$i n";
}

//检查是否是最后一页
if ($pages!=0 && ($newoffset/20)!=$pages)
{
print "下一页 n";
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630807.htmlTechArticle简单实用php mysql分页代码 简单实用php教程 mysql教程分页代码 $qh=mysql_query(select count(*) as rcnt from table where your_condition_here order by whatever); $dat...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.