davenok Posted December 21, 2015 Share Posted December 21, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/299942-persistent-filters-and-cookies/ Share on other sites More sharing options...
ginerjm Posted December 21, 2015 Share Posted December 21, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/299942-persistent-filters-and-cookies/#findComment-1528413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.