实现“上一页”和“下一页按钮
Release: 2016-05-20 09:09:33
Original
1725 people have browsed it
//本例子摘自phpbuilder.com
//稍加翻译
//
$limit=20; // 每页显示的行数
$numresults=MySQL(和PHP搭配之最佳组合)_query("select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER");//换成你所需要的sql语句
$numrows=MySQL(和PHP搭配之最佳组合)_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
// 得到查询结果
$result=MySQL(和PHP搭配之最佳组合)_query("select id,name,phone ".
"from TABLE where YOUR CONDITIONAL HERE ".
"order by WHATEVER limit $offset,$limit");
// 现在显示查询结果
while ($data=MySQL(和PHP搭配之最佳组合)_fetch_array($result)) {
// 在这里插入您要显示的结果以及样式
}
// 显示按钮
if ($offset!=1) { // bypass PREV link if offset is 1
$prevoffset=$offset-20;
print "上一页 \n";
}
// 计算页面数
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i$newoffset=$limit*($i-1);
print "$i \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "下一页\n";
}
?>
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31