Return to post-query page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Return to post-query page

Post by phillyrob »

I have a setup where you can query for data and get a result. It works fine. You can then click on a link in the result to go to another page. I then want the user to be able click a link and return to the previous page (the results page) post query and not have to search again. Can someone explain how that can be done? return to the p
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Return to post-query page

Post by panic! »

a multitude of ways.

Code: Select all

<a href="javascrpt:void(0)" onclick="history.go(-1)">go back</a>
(never personally used, but give it a go)

or you could store the result in a session/cookie.
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Re: Return to post-query page

Post by phillyrob »

I'll try the javascript method, and thanks. Panic
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Re: Return to post-query page

Post by phillyrob »

Sorry Panic I tried the Javascript, but not familiar with it. I put it in verbatim (probably shouldn't have of course).Can you elaborate? Where do I pluge in the page that I want it to return to.
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Return to post-query page

Post by panic! »

put this link on the page after the results page, then they can click it and go back to the results, they will however be warned that they will be POST-ing data again.


I think a better way would be something like this

Code: Select all

 
 
if(!$_POST['query'] && $_COOKIE['query'])
{
$_POST['query']=$_COOKIE['query'];
}
else
{
setcookie('query',$_POST['query'],time()+3600,'/');
}
 
what this does it, looks for the query in the POST data, if it's not there, look in the cookie 'query' if it can find this set the POST data for query to the cookie.

If it finds the POST data straight away, it sets the cookie for a future time if there is no POST data for query.

Obviously change the variable $_POST['query'] to the name of your input field.
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Re: Return to post-query page

Post by phillyrob »

Thanks I will try it. I appeciate it.
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Re: Return to post-query page

Post by phillyrob »

I am using the javascript and got it to work, only thing is it won't work in ie, works fine in firefoex. Have you seen that? Is there a work around.
Post Reply