Jump to content

How would I do pagination in PHP?


johnsmith153

Recommended Posts

Hi,

 

I have a db with 2000 records (can vary).

 

Pagination:

 

I need to show user number of records in the db then display 100 per page.

 

What is the best method:

 

(1) dump entire db to PHP then sort through records, only displaying 100.

 

(2) Somehow find out number of records in the db (in this case 2000) then return TOP 100 only.

 

It is possible the table could hold 500,000 records at one point.

Link to comment
https://forums.phpfreaks.com/topic/170085-how-would-i-do-pagination-in-php/
Share on other sites

There are loads of pagination tutorials out there, but for your problem, I would number 2. Number 1 can cause a lot of information to be caught up in the memory, a vast majority of which you won't end up using so it's a waste. It's much less of a CPU/memory drain to calculate how many rows there are in the table (a simple SQL statement) and grab the ones that are required.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.