Jump to content

How to paginate a search?


lopes_andre

Recommended Posts

http://www.phpfreaks.com/tutorial/basic-pagination

 

Take a look at the tutorial on pagination.

 

Thanks for your reply.

 

I'am using a script like this.

 

My problem is the following:

 

I have a complex code that generate an SQL query, but when I go to page 2 or 3 or ... I lost the query...

 

My question, how to deal with a page that receives values from a form then generates a query... how to paginate in a situation like this one.

 

form --> generate sql query --> show results in pages.

 

 

Sorry for my bad english.

 

 

Best Regards,

André.

can't help you without seeing your (relevant) code...

 

in general though, the query will have to be run every page load.  The point of pagination is that instead of retrieving all of your rows every page load, you narrow it down to a specific range, depending on what "page" you are on.  So if you want to for instance show 10 rows per page, and you are on page 1, the query will be the same, but you would create a limit of 0,9. Page 2 would be a limit of 10,19, etc... so the same query is being run, just the limit is changing. 

 

If it is a complex query that you do not want to be running every time, I would suggest looking into either initially grabbing the data and putting it into a flatfile or array and basing the pagination off of the flatfile or array (instead of querying the db every time), or having another (temporary) table in your database that is populated with the results of the initial query, and basing your pagination off that.

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.