如何创建分页器链接
我正在尝试创建一个基于 mysql 表中的行数创建的动态页面链接。我想每页显示 10 个结果,并希望 php 脚本创建指向其他页面的链接。
所以我正在考虑使用 num_rows 并将其除以 10,但是如果我有 53 行,则返回将是 5.3,因为我需要 6 页而不是 5。我正在考虑使用 round 函数并通过 for I 循环它语句直到 $pages > $rows_rounded。每 10 行添加一个指向页面的链接($i) 这是实现此目的的最佳方法还是有其他更简单的方法可以采用?
I am trying to create a dynamic page links created based on the number of rows in a mysql table. I would like to display 10 results per page and wish to have the php script create links to additional pages.
So I was thinking of using the num_rows and dividing it by 10 however if I have 53 rows the return would be 5.3 where as I would need 6 pages and not 5. I am thinking of using the round function and looping it through a for I statement until $pages > $rows_rounded. And every 10 rows add a link to pages($i) Is this the best method to acheive this or there an alternative simpler route to take?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我制作的 pagenator 类。 getCurrentPages() 返回您应该在数组中显示的所有页面。因此,如果您在第一页,并且您想要显示总共 9 页,您将得到一个数组 1-9。然而,如果您在第 10 页,您将返回数组 6-14。如果总共有 20 页并且您在第 20 页,您将返回数组 11-20。
编辑(用法):
pagenator class I made. getCurrentPages() returns all the pages you should be displaying in an array. so if you are on page one, and you want to display a total of 9 pages, you would get an array 1-9. if you were on page 10 however, your would get back an array 6-14. if there are 20 total pages and you are on page 20, you would get back an array 11-20.
EDIT (USAGE):
for 循环的想法听起来不错,您可以使用以下内容:
但是您需要考虑检测当前页面,因此,例如,如果当前页面为 3,则测试它可能是一个好主意在您的 for 循环中,如果回显第三个链接,可能会添加一些额外的类以使您能够对其进行样式设置。
The idea of a for loop sounds like a good one, you would use something like:
But you need to consider detecting the current page, so if, for example, the current page was 3, it might be a good idea to test for that in your for loop and if echoing the 3rd link maybe add some extra class to enable you to style it.