简体   繁体   English

CI Codeigniter分页而不计算db的所有结果

[英]CI Codeigniter pagination without counting all results from db

i was wondering if anyone as a good idea or solution to use pagination without counting all records before splitting results 我想知道是否有人将分页而不是在分割结果之前对所有记录进行计数是一个好主意或解决方案

i mean when paginating with default CI library we must set total number of records, and this will be too huge for high amount of records don't you think? 我的意思是,在使用默认CI库分页时,我们必须设置记录总数,这对于大量记录来说太大了,您认为吗?

what if i have more then 500'000 records to be paginated? 如果我还有500,000条记录需要分页怎么办?

so my idea was trying paginating using ranges somenthing like : 所以我的想法是尝试使用诸如以下的范围进行分页:

page 1 => query LIMIT 0,10 第1页=>查询LIMIT 0,10

page 2 => query LIMIT 10,20 第2页=>查询LIMIT 10,20

but i found many problems: 但是我发现了很多问题:

1) i anyway need to count all records to retrieve page numbers 2) how to save ranges ([1,10] [10,20] ... etc)? 1)我仍然需要计算所有记录来检索页码2)如何保存范围([1,10] [10,20] ...等)?

thanks to anyone could help me 感谢任何人都可以帮助我

If you use your solution where you use a LIMIT to get each page, then use the FOUND_ROWS() . 如果您在使用LIMIT来获取每个页面的位置使用解决方案,请使用FOUND_ROWS()

It will give you the amount of rows totally excluding the limit . 它会为您提供完全不包括限制的行数 This way you don't need two queries where the first retrieves the specific range and the other one retrieves the total rows. 这样,您就不需要两个查询,其中第一个查询检索特定范围,而另一个查询检索总行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM