我有一些 PHP 代码,它从我的数据库中返回所有记录。每页我需要 10 个结果。如何对结果进行分页?不知道怎么写一段负责显示页码的代码...<?php$query = $link->query("SELECT * FROM news WHERE category='rhythmix' ORDER BY subject DESC"); while($output = $query->fetch_assoc()){$text = $output['news'];$text = str_replace('[video]','<div class="video-container">',$text);$text = str_replace('[/video]','</div>',$text);$text = str_replace('[media]','<center>',$text);$text = str_replace('[/media]','</center>',$text);$embera = new \Embera\Embera();echo $embera->autoEmbed($text);}?>
2 回答
holdtom
TA贡献1805条经验 获得超10个赞
以这种方式将 LIMIT 添加到您的查询中:
SELECT *
FROM news
WHERE category='rhythmix'
ORDER BY subject DESC
LIMIT 0, 10;
第一个数字 (0) 是结果集上的起始位置,第二个数字 (10) 是您要显示的结果数(偏移量)。
显示第二页:
...LIMIT 10, 10
如果您总是想显示 10 个结果,您只需将 10 添加到 LIMIT 的第一个数字。
婷婷同学_
TA贡献1844条经验 获得超8个赞
更改您的查询以阅读
$query = $link->query("SELECT * FROM news WHERE category='rhythmix' ORDER BY subject DESC LIMIT 0, 10");
显示前 10 行。下一组 10 行可以使用
...LIMIT 10, 10");
等等。. .
- 2 回答
- 0 关注
- 264 浏览
添加回答
举报
0/150
提交
取消