I have have a search routine/display (in php) that is so common it must be in a library. Any way, I search a database and find, say, 1000 records. I only want to display 50 at a time. That's easy to do. You don't need to know how many total records there are, just remember where you were and configure the limit construct for the next chunk.
But how do you calculate the number of pages available unless you run the query 'wide open' at least once to get the 'grand total'? Seems a waste to do that.
I thought about caching the unlimited query in $_SESSION. I've never done that and even with experimentation I'm not sure I want to.
What is the common practice of discovery. How do you get the total number of records other than by running a query twice?