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 (emptyempty($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 "<a href="$php_self?offset=$preoffset">前一页</a> ";
}
//计算总共需要的页数
$pages=ceil($nr/20); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=20*$i;
print "<a href="$php_self?offset=$newoffset">$i</a> ";
}
//检查是否是最后一页
if ($pages!=0 && ($newoffset/20)!=$pages)
{ //开源代码www.bcty365.com
print "<a href="$php_self?offset=$newoffset">下一页</a> ";
}
热文精选
更多资讯推荐
更多- Stable Diffusion 2.0 发布,加强成人内容过滤
- .NET 7 正式发布
- A3Mall 开源商城系统 v2.1 发布
- FydeOS v14 版本更新:优化输入法体验+重构安卓子系统+全新应用启动器
- ThinkPHP V6.0.8版本发布——多环境变量配置支持
- 毕昇 JDK 8u292、11.0.11 发布!
- KubeVela 1.0:开启可编程式应用平台的未来
- Eclipse 4.19 稳定版发布
- 阿里巴巴 Arthas 3.5.0 版本发布,支持反编译打印行号和统一鉴权
- Debian 11 Bullseye 即将进入冻结,Debian 13 代号 Trixie
- Rancher 2.5 发布,新增支持边缘集群的 GitOps
- FlashDB IoT 超轻量级嵌入式数据库