How to create pagination in PHP?

pagination with php with a possible infinite limit

  • I know how to create pagination with php if I have 25 results with 5 results each page, but what about if the limit number can change in the hundreds everyday? How can I write something where the php itself will create more pages if the row count itself changes?

  • Answer:

    Take a look at: http://www.phpclasses.org/package/1239-PHP-Spliting-database-query-result-sets-between-pages-.html It should solve your problem... Also you can search for other pagination classes to check the source code and/or use as it is!

carlgcode at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

usually pagination is made in two steps: query to count the number of records unsig the prevoius query, create the query using LIMIT to retrieve the current page So i don't see the problem o_O, if tomorrow the number of elements change then the first query would return a different result.. and you wont have problems with the pagination Later, if you want to improve performance you could set a cache system for the count query. Hope this helps

pleasedontbelong

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.