Jump to content

[SOLVED] Back from search results


eoeowner

Recommended Posts

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?

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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... ;)

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

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.