Mysqli PHP Ajax分页 [英] Mysqli php ajax Pagination

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

问题描述

有人可以向我解释如何解决此问题吗?

can someone please explain to me how to approach this issue?

我有一个包含4000条记录的表,一个选择选项和一个用于过滤该表的搜索字段

I have a table with 4000 records, a select option and a search field to filter out the table

但是我正试图找出设置分页的最佳方法.

however I'm trying to figure out the best way to set up pagination.

第一种方法: 我是否应该对数据库进行一次查询,并用所有记录填充表,然后使用javascript设置分页,以便能够搜索不仅在当前页面上显示的记录?

1st Approach: Should I make one query against the database and populate the table with all records and then set up the pagination with javascript so I can be able to search for records that are not only shown on the current page?

第二种方法 用PHP设置分页,通过ajax对每个页面进行查询?但是,如果我需要搜索不在当前页面上的记录,恐怕这种方法将不允许我过滤掉表格.

2nd Approach Set up the pagination with PHP, make a query via ajax for each page? however I'm afraid that this approach would not allow me to filter out the table if I need to search for a record that is not on the current page.

推荐答案

第一种方法:绝对不行,不建议加载大量结果而无所事事.
第二种方法更有意义.您可以在SELECT语句中使用LIMIT语句来确定所需的记录.前任.如果您对每页10个元素进行分页,则可以

1st approach: definitely not, loading large number of results for nothing is not recommended.
2nd approach makes more sense. You can use the LIMIT statement inside your SELECT statement to decide which records you want. Ex. if you paginate on 10 elements perpage, you could do

 SELECT * FROM Table LIMIT 10

然后

SELECT * FROM Table LIMIT 10,10

,依此类推.索引从0开始.

and so on. Indexes start at 0.

请注意,您甚至都不需要Ajax来执行此操作,您的next按钮可以为页面的下一次加载指定偏移量.根据您的知识,页面其余部分的大小(最大限度地减少加载时间),...

Note that you don't even need Ajax to do that, your next button can specify the offset for the next load of the page. It's a choice based on your knowledge, the size of the rest of the page (minimize load time), ...

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

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