Jump to content

Persistent Filters and cookies


Recommended Posts

Hello all,


I have a simple PHP page that queries a database and outputs the result set in an HTML table. It works fine.  However, the result set is relatively large (2500ish records), so I want to apply a filter. Added an HTML form to the page that lets us filter the criteria. Again, works great. (Used GET method so that the URL could be linked).


Here's where my problem comes about. My boss wants the filters to be persistent, both within and between sessions. My first thought was cookies.. so I created a function called Filter() and call it at the top of my PHP document. It reads the cookie and applies the filters into the SQL statement. This works, but is rather kludgy. The problem I have is that when I first access the page, it doesn't seem to see the filters, it displays the full 2500ish record set. However, if I do a CTRL-R to reload the page, it then loads the filters correctly... it's almost like it renders the page before it can read the cookies in the initial pass.


Any thoughts on how to improve this, or am I taking a totally wrong approach?


Link to comment
Share on other sites

Does your page present any kind of selection page for the user to decide what is to be done? When the page first loads, retrieve the cookies and either display them on the page you first show, or hide them on the page, or just run the query with them.  If there are no cookies I would modify the script to send a first screen that asks the user to make his filter choices and then create the cookies and then run the query.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.