使用Mysql和PHP的分页帮助 [英] Pagination with Mysql and PHP Help

查看:156
本文介绍了使用Mysql和PHP的分页帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用下一个和上一个链接创建分页,而不是使用1,2,3..etc.

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

所以我在数据库中说了项目1,2,3,4,5,每个项目都在一页上.

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

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

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

到目前为止,我已经开始检索数据库中的所有项目,并创建了一个循环以吐出每个项目中的所有URL.但是我不太了解剥离相邻项目以外的所有项目的最佳方法.这是我到目前为止的循环.

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为$ url): echo $ url ['url']; endforeach;

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

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

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...

谢谢,伙计们!

推荐答案

这里是用于分页表格数据的一种精巧资源,而无需编写您自己的代码或完全不需要任何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.

这篇关于使用Mysql和PHP的分页帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆