使用 Mysql 和 PHP 帮助进行分页

发布于 2024-09-27 19:26:58 字数 409 浏览 1 评论 0原文

我正在尝试创建一个仅包含下一个和上一个链接而不是 1、2、3...等的分页。

所以我在数据库中有第 1,2,3,4,5 项,每个项都在一页上。

如果我在第 2 项页面上,我想要第 1 项页面的上一个链接和第 3 项页面的下一个链接...等等

到目前为止,我开始检索数据库中的所有项目并创建一个循环来吐出所有内容每个项目中的 URL。但我不太知道去除除相邻项目之外的所有项目的最佳方法。这是我到目前为止的循环。

foreach($item_url 为 $url): 回声 $url['url']; 结束foreach;

这会吐出所有 URL...但是我如何继续仅列出相邻项目而不计算我所在的当前项目...我尝试使用 next($url);如果指针与当前项目匹配,则移动指针,但它不起作用...

谢谢,伙计们!

I am trying to create a pagination with just next and previous links instead of 1,2,3..etc.

So I have say item 1,2,3,4,5 in the database and each item is on one page.

If I am on item 2 page I would like a previous link for item 1 page and a next link for item 3 page...etc

So far I got up to retrieving all the items in the database and created a loop to spit out all the URL in each item. But I don't quite know the best way to strip off all the items except the adjacent items. This is the loop I have so far.

foreach ($item_url as $url) :
echo $url['url'];
endforeach;

This spits out all URL...But how do i proceed to list only the adjacent items and not count the current item I am on...I tried using next($url); to move the pointer if it matches the current item but it didn't work...

Thanks, guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2024-10-04 19:26:58

这是一个用于分页表格数据的简洁资源,无需编写自己的代码,也不需要任何 PHP。将所有结果放入表格中(如果您愿意,也可以通过 JSON 输出它们)现在,应用 DataTables 插件表 id 并告诉它进行分页。瞧,即时分页,无需脑损伤。

Here's a neat resource for paging tabular data without the headache of writing your own code or the need for any PHP at all. Throw all the results into a table (or output them via JSON if you are so inclined) Now, apply the DataTables plugin to the table id and tell it to do pagination. Voila, instant pagination, no brain damage required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文