eoeowner Posted May 16, 2007 Share Posted May 16, 2007 Hi all, long time lurket, first time poster. So, I run a form based query to search my mySQL database and display the results. All good, works fine. You choose the Category, Medium and Genre from the drop downs and then the query is populated based on the result eg SELECT * WHERE Category = $Category, Medium = $Medium... and so on. When the query is run on the next page, it nicely prints up the results. Here is my question. From the result page, you can click on a particular item and it sends the user to a page that displays all of the information for that item (link with whatever.php?id=$id). BUT, when the user hits the back button, the page has expired. How do I let the user go back to the search page to display the original results? For a working example, check out the site - www.emporiumofevil.com - and use the advanced search function from the left side bar. Fill out whatever in the drop downs (music is fully populated) and then submit the form. You'll get the search results and then click on the thumb to see the product details. If you then press back, you'll get the expired page. To make this trickier, the user may arrive at the product page from other random links (eg random product also on the left side bar) so they don't always come through from the search. Any thoughts? Quote Link to comment Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 The only ways to avoid an expired form result page is to either use method="GET" instead of method="POST" in your search form, or, if you insist on using POST, you would need to use a header redirect to manually send the user to a result page.. This would be more involved, since you would need to temporarily store the search results in a database in order to preserve the results while the user is sent to the new page to view the results.. The side benefit of this method is that you would be able to setup a cache system quite easily to help reduce server load for common searches.. Definitely not necessary though unless you have a very busy site.. Best of luck! Quote Link to comment Share on other sites More sharing options...
Chesso Posted May 16, 2007 Share Posted May 16, 2007 Or if you have a seperate results page, cross over variables back and forth so you can just easily re-populate the exact same search result again. Maybe not efficient, but it's not difficult to do. Or go with the temporary cache method. Quote Link to comment Share on other sites More sharing options...
eoeowner Posted May 16, 2007 Author Share Posted May 16, 2007 Hmmm... okay, so I'll try the GET method and see if that will work. Yeah, I think that will do the trick. The reason I use the POST method is because I redirect to the same basic page with includes (or requires) in it and therefore the page I go to has "...php?main=16" in it. Will that effect the GET method? If I do action="...php?main=16" will it automatically make redirect to "...php?main=16&category=Music&Genre=Punk..." or whatever? Quote Link to comment Share on other sites More sharing options...
radar Posted May 16, 2007 Share Posted May 16, 2007 Or as the way I would do it (and have done it) is include a little javascript to open up a url in a popup window -- that shows the information -- now yes that can be a bad thing, but i haven't had any complains from any of my clients about popups being blocked from popup blockers... And most of my clients' clients use shared computers.. So either way you can try it... Quote Link to comment Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 Will that effect the GET method? If I do action="...php?main=16" will it automatically make redirect to "...php?main=16&category=Music&Genre=Punk..." or whatever? A more reliable way to do this would be a hidden form field for the "main" variable, such as: <form action="search.php" method="GET"> <input type="hidden" name="main" value="16" /> ... </form> Quote Link to comment Share on other sites More sharing options...
eoeowner Posted May 16, 2007 Author Share Posted May 16, 2007 Yeah, I was thinking that. I'll try out the GET method and post how I go. I have considered the pop up thing, but I did a survey as I was building the site and people unanimously voted against it. So, I've gone with the one window which, obviously has it's limitations. Thanks for the advice, I'll give it a go and let you know how I went... Quote Link to comment Share on other sites More sharing options...
radar Posted May 16, 2007 Share Posted May 16, 2007 Also another way would be to use javascript so that when the person clicks on whatever, the list doesnt actually go away its just hidden, and the info is displayed, then they hit a "back" button which doesn't actually take them back, it just activates the javascript again -- ive done it that way too (recently -- as in on the admin panel of the site i am working on now). Quote Link to comment Share on other sites More sharing options...
Chesso Posted May 16, 2007 Share Posted May 16, 2007 Don't forget that, if I remember correctly there is a limit to how much information you can pass along using the GET method, I think that's the only real practical difference. Quote Link to comment Share on other sites More sharing options...
eoeowner Posted May 16, 2007 Author Share Posted May 16, 2007 Perfect! I've changed the code as suggested and it worked a treat. I can now click on the back button and go back to the results of the search. I don't know about the limit of the URL length, but I didn't have any problems. Works a treat Quote Link to comment 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.