复制代码 代码如下:
<?php
header("content-type:text/html;charset=utf-8");
//数据库连接
$conn = mysql_connect("localhost", "root", "111") or die("not connnected : ".mysql_error());
mysql_select_db("test", $conn);
mysql_query("set names utf8");
//查询共有多少行数据
$sql1 = "select count(*) from user";
$ret1 = mysql_query($sql1);
$row1 = mysql_fetch_row($ret1);
$tot = $row1[0];
//每页多少行数据
$length = 5;
//总页数
$totpage = ceil($tot / $length);
//当前页数
$page = @$_GET['p'] ? $_GET['p'] : 1;
//limit 下限
$offset = ($page - 1) * $length;
echo "<center>";
echo "<h2>php padding</h2>";
echo "<table width='700px' border='1px' >";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>USER</th>";
echo "<th>PASS</th>";
echo "</tr>";
//将查询出来的数据用表格显示
$sql2 = "select * from user order by id limit {$offset}, {$length}";
$ret2 = mysql_query($sql2);
while ($row2 = mysql_fetch_assoc($ret2)) {
echo "<tr>";
echo "<td>{$row2['id']}</td><td>{$row2['name']}</td><td>{$row2['pass']}</td>";
echo "</tr>";
}
echo "</table>";
//上一页和下一页
$prevpage = $page - 1;
if ($page >= $totpage) {
$nextpage = $totpage;
} else {
$nextpage = $page + 1;
}
//跳转
echo "<h3><a href='index.php?p={$prevpage}'>上一页</a>|<a href='index.php?p={$nextpage}'>下一页</a></h3>";
echo "</center>";
核心点:
<1>“$sql2 = "select * from user order by id limit {$offset}, {$length}";”,$offset、$length和页数之间的关系。
<2>上一页和下一页的获得方式,以及临界点。
php分页代码
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 纯音入心系列纯音乐《中央民族乐团-古筝传奇》1CD[MP3][253.1MB]
- 江玲.1989-这样你才爱我,是吗?【新作有声】【WAV+CUE】
- 郭美美.2010-我是郭美美【华纳】【WAV+CUE】
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]