What actually happens during pagination?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BZorch
Forum Commoner
Posts: 45
Joined: Mon May 02, 2005 10:42 pm

What actually happens during pagination?

Post by BZorch »

I have searched far and wide for an explanation to actually what happens when you paginate from an MySQL database using PHP. I have read many tutorials and I have figured out how to do it. But nothing ever discusses where the linked pages in the pagination are actually stored on the server, client, or elsewhere? Can anyone enlighten me?

Thank you.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

A very basic level of pagination consists of the following variables:
  • A query
    Total Number of Records
    Records To display per page
    Current Low record

The rest is a matter of modifying the query to fit the parameters and determining what page you are currently on.

Also, make life easy. Use GET and not POST
BZorch
Forum Commoner
Posts: 45
Joined: Mon May 02, 2005 10:42 pm

Where are the temporary pages stored?

Post by BZorch »

Thank you. It does seem to be a straight forward process to create the pagination, but when you create the links for however many pages, where are the pages stored that the links reference. Since it dynamic and the pages are temporary and users are querying all of the time, are the pages in an array, cached in the browser, temp files on the server?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

if the pages are being dynamically created, say with php, then the pages don't exist anywhere because they haven't been created yet.

If the pages are static then they are still residing on the server waiting to be called.

When using pagination and php,mysql what happens is a request is sent to the server to pagination.php, or whatever, and it does a query something like

Code: Select all

Select * FROM myPages LIMIT $start, $numberOfRows
$start being where to start in the result set and $numberOfRows being how many rows of results to return. It is then up to you as the programmer to calculate the $start position of the rows to return based on things like a next link or an actual page number to jump to.

Hopefully that helps.

phpScott
BZorch
Forum Commoner
Posts: 45
Joined: Mon May 02, 2005 10:42 pm

I think I understand

Post by BZorch »

Thank you. With your explanation and a little more detailed look at the scripts, I think I understand what is actually happening. Basically, the links added with the pagination script tell where to begin to display the records.

So when you click on each link the query is run again, but starts retrieving records at the specified point. So the start records are passed by the first query. So the results are always in the database and are not retrieved until needed. Is this correct? This is very helpful.
Post Reply