PHP/MySQL 分页
我是 php 和 sql 的新手,我有一个关于如何实现 sql 查询的小问题,可以:
- 以数据库中的 5 个条目为例,插入 它们位于第一页(1-5)
- 而不是从同一数据库中获取接下来的 5 个条目并将它们插入到另一页(5-10)
等等:)
谢谢)
I am new to php and sql, and i have one tiny question about how to realize sql query , that can:
- Take for example 5 entries from DB, insert
them on 1st page (1-5) - Than take next 5 entries from same DB and insert them on another page (5-10)
and so on :)
Thank you )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请阅读 MySQL SELECT 帮助页面上的 LIMIT 部分。如果要显示可用的总行数,可以进行额外计数,或使用 ROW_COUNT 函数。
Read the LIMIT section on the MySQL SELECT helppage. If you want to display the total number of rows available, you can either do an extra count, or use the ROW_COUNT function.
有几种方法可以做到这一点,我认为最快的性能是以下一种:
您应该使用的东西:
There are several ways to do this, I think the fastest performance is following one:
Stuff you should use:
如果您的查询没有返回大量结果,请考虑使用 Jquery 通过 Tablesorter 函数对其进行分页。它需要一个格式正确的 HTML 表和页面、排序等,如果您不希望,则不需要额外的查询变量。它比采用成熟的 PHP 分页路线要容易得多,而且对于用户来说速度也快得多。
我个人最喜欢的例子在这里: http://datatables.net/
它可能不完全满足您的需求,但它对于许多应用程序来说都很酷。如果您这样做,请不要忘记使用 thead 和 tbody 设置表格格式,以便它可以正确拾取表格元素。
If your query does not return a prohibitive amount of results, consider using Jquery to page it with a Tablesorter function. It takes a properly formatted HTML table and pages, sorts, etc on the fly...no need for additional query variables if you don't wish. It's SO much easier than going the full-blown PHP paging route, and is much faster for the user.
My personal favorite example is here: http://datatables.net/
It may not fully suit your needs, but it is cool for many applications. If you do it, just don't forget to format your table with thead and tbody so that it can properly pick up the table elements.