简体   繁体   English

使用Mysql和PHP进行分页

[英]Pagination with Mysql and PHP Help

I am trying to create a pagination with just next and previous links instead of 1,2,3..etc. 我正在尝试仅使用下一个和上一个链接而不是1,2,3..etc创建一个分页。

So I have say item 1,2,3,4,5 in the database and each item is on one page. 所以我说数据库中的项目1,2,3,4,5,每个项目都在一页上。

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 如果我在项目2页面上,我想要项目1页面的上一个链接,并在项目3页面的下一个链接...等等

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. 到目前为止,我已经开始检索数据库中的所有项目,并创建了一个循环以吐出每个项目中的所有URL。 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']; foreach($ item_url为$ url):echo $ url ['url']; endforeach; 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); 这会吐出所有URL ...但是我如何继续只列出相邻的项目而不计算我当前所在的项目...我尝试使用next($ url); to move the pointer if it matches the current item but it didn't work... 如果指针与当前项目匹配,则移动指针,但是它不起作用...

Thanks, guys! 多谢你们!

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. 这是用于分页表格数据的一种精巧资源,无需编写您自己的代码或完全不需要任何PHP。 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. 将所有结果都放入表中(或者如果愿意,可以通过JSON输出)现在,将DataTables插件应用于表id并告诉它进行分页。 Voila, instant pagination, no brain damage required. 瞧,即时分页,不需要大脑损伤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM