memento
memento

Reputation: 97

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?

what if i have more then 500’000 records to be paginated?

so my idea was trying paginating using ranges somenthing like :

page 1 => query LIMIT 0,10

page 2 => query 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)?

thanks to anyone could help me

Upvotes: 1

Views: 1610

Answers (1)

rzetterberg
rzetterberg

Reputation: 10268

If you use your solution where you use a LIMIT to get each page, then use the 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.

Upvotes: 1

Related Questions