大PHP数组分页 [英] Large PHP Arrays pagination

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

问题描述

我有一个数组,该数组具有超过10k的结果(由MySQL查询生成),我想知道对它进行分页的最佳实践是什么?首先提取所有数据,然后将其拆分为页面,或者还有另一种更快/最好的方法?

I have an array that has over 10k results (generated by a MySQL query) and I wonder what is the best practice for paginate it? Extract all the data first then split it to pages or there is another faster/best way?

推荐答案

使用MySQL的

Use MySQL's LIMIT syntax to only retrieve the desired results from the database before it even reaches your PHP code.

类似这样的东西:

$offset = 0;
$per_page = 25;

$query = "SELECT * FROM `blah` LIMIT $offset, $per_page";

...

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

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