Ajax 数组显示控制 - 分页

发布于 2024-09-25 10:55:06 字数 334 浏览 0 评论 0原文

我有一个区域,其中填充了来自 php mysql 查询的大约 100 条记录。

需要添加 ajax 分页含义,首先加载 10 条记录,然后在用户单击“+”字符时,它会填充下 20 条记录

。因此,该区域不会一次显示全部,而是显示 20 条,然后单击,然后显示下 20 条,下一个...等等,没有刷新。

我应该将 100 条记录转储到会话变量中吗?

每次用户点击下一页触发器时,我是否应该调用 Myqsl 查询?

不确定什么是最好的方法……或者解决这个问题的方法。

我担心数据库将从 100 个增长到 10,000 个。

非常感谢任何帮助指导。

I have an area which gets populated with about 100 records from a php mysql query.

Need to add ajax pagination meaning to load 10 records first, then on user click to let's say "+" character it populates the next 20.

So the area instead of displaying all at once will display 20, then on click, then next 20, the next... and so on with no refresh.

Should I dump the 100 records on a session variable?

Should I call Myqsl query every time user clicks on next page trigger?

Unsure what will be the best aproach...or way to go around this.

My concern is the database will be growing from 100 to 10,000.

Any help direction is greatly apreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻许诺言 2024-10-02 10:55:06

如果您有一个经常查看(但不经常更新)的大型记录集,请查看 APC 来缓存数据并在会话之间共享它。您还可以创建一个静态文件,当数据更改时会重写该文件。

如果需要在页面上对数据进行排序/操作,您将需要限制加载的记录数量,以防止 JavaScript 运行时间过长。 ExtJS 有一些很好的小部件可以做到这一点,只需为其提供 JSON 数据(在记录集上使用 PHP 的编码方法)。我们与 Oracle 进行了一次交谈,并相当轻松地完成了 20 条记录的分页。

如果您的大型记录集经常更新,并且数据必须“实时”准确,那么您将面临一些重大挑战。我会关注 comet、ape 或 webworkers 的轮询/推送解决方案,并构建 API 来仅处理“核心”数据的更新——同样,可能缓存在服务器上,而不是每次都从数据库中提取。

If you have a large record set that will be viewed often (but not often updated), look at APC to cache the data and share it among sessions. You can also create a static file that is rewritten when the data changes.

If the data needs to be sorted/manipulated on the page, you will want to limit the number of records loaded to keep the JavaScript from running too long. ExtJS has some nice widgets that do this, just provide it with JSON data (use PHP's encode method on your record set). We made one talk to Oracle and do the 20-record paging fairly easily.

If your large record set is frequently updated, and the data must be "real time" accurate, you have some significant challenges ahead. I would look at comet, ape, or web workers for polling/push solution and build your API to only deal in updates to the "core" data--again, probably cached on the server rather than pulled from the DB every time.

时光倒影 2024-10-02 10:55:06

您的 ajax 调用应该调用一个页面,该页面仅从数据库中提取所需的确切行数。因此,从第一页的查询中选择前 20 行,依此类推。您的 ajax 调用可以采用一个名为 pagenum 的参数,具体取决于您从数据库中实际提取的记录。不需要会话变量。

your ajax call should call a page which only pulls the exact amount of rows it needs from the database. so select the top 20 rows from the query on the first page and so on. your ajax call can take a parameter called pagenum and depending on that is what records you actually pull from the database. no need for session variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文