Jump to content

How to add search tool to a pagination php script


phpnewbie34

Recommended Posts

How do I carry the search term over in the address bar w/ pagination?

 

It can be done many different ways. How you do it depends on how you want it to work.

 

1. Normally on your pagination navigation links you will add a parameter to identify which page to show (e.g. showdata.php?page=3). You could add an additional parameter to also pass the search term. If you only have a single search field this isn't a terrible solution. But, if you add more fields, it definitely makes the URL ugly.

 

2. You could store the search value in a cookie. Then on each load of the pagination script check to see if there is a value in the cookie for the search string. If you want the search string to persist between sessions (perhaps the user has a preferred view) this makes sense. For pagination, I only store things in cookies such as 'preferences' such as the number of records per page.

 

3. Session data. This would be my preferred approach.

 

But, no matter where you store it, the logic would work something like this:

 

1. Check if new search values have been sent (i.e. POST data). If so, use that data for the query and save it to wherever you are storing it.

2. If no new search data was passed, check if there is existing search criteria where you store it (Cookie, Session, GET, etc.). IF so, use it

3. If no new data was passed and no data exists in the saved location, then assume there is no search criteria.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.