View Full Version : Returning to a db page keeping the same search parameters

11-14-2010, 03:56 PM
I have a db page and when you leave the page to post selections on return you come back to the same id row you selected beacause I have this code on the select.php page (thx to Mattf and others)

$back = isset($_GET['id']) ? '#' .intval($_GET ['id']) : '';
header( 'Location: indexfull2.php'.$back );
This is fine if the user hasn't input any search parameters, if they have made a search for 'beatles' they would return to the page at the id row they had selected but it would be within the entire database page rather than the search beatles page with 20 or so rows.
So is there away to save the search parameters on exit from the db page and re select them on the way back, rather than selecting the entire db it normally does.
The code

$var = @$_GET['a'] ;
$search1 = ($var);

$var = @$_GET['b'] ;
$search2 = ($var);

$var = @$_GET['c'] ;
$search3 = ($var);

$var = @$_GET['d'] ;
$search4 = ($var);

$var = @$_GET['e'] ;
$search5 = ($var);

$var = @$_GET['f'] ;
$search6 = ($var);

$var = @$_GET['g'] ;
$search7 = ($var);


mysql_select_db("a2149809_MV") or die ("Unable to select database");

$query = "SELECT * FROM `music vidz` WHERE `Artist` LIKE \"%$search1%\"
AND `Title` LIKE \"%$search2%\" AND `Disc` LIKE \"%$search3%\"
AND `Era` LIKE \"%$search4%\" AND `Date Added` LIKE \"%$search5%\"
AND `AR` LIKE \"%$search6%\" AND `Quality` LIKE \"%$search7%\" order by `Artist`";



11-14-2010, 06:51 PM
I can use this to retrieve the url

$fulluri = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

Trying to use the search button to send this info to the select page by putting this href in the search button

<a uri="<?php echo $fulluri.'" href="select.php?uri='.$fulluri.'">
but having no luck, I will then have to collect that on the select page, but not entirely sure how, anyone help?

11-14-2010, 08:09 PM
Use sessions.

11-14-2010, 09:13 PM
Matt does this code mean I have the session variable stored as this url, it does echo the right url but on the same page, obviously I want to retrieve it on another page

echo "http://" .$_SESSION;

11-15-2010, 02:00 AM
Managed to do it

db page


select page

$redirect = $_SESSION['comeback'];

$back = isset($_GET['id']) ? '#' .intval($_GET ['id']) : '';
header( 'Location: http://'. $redirect.$back);

Thanks for the tip Matt should I add anything to this code to make it proper?

11-15-2010, 03:04 PM
Continuing from above does anyone know why this href would produce this

$redirect = $_SESSION['comeback'];

<a href="<?php echo "$redirect" ?>" style="text-decoration:none">
<input type="button" value="Back To The Database" /></a>

11-15-2010, 03:09 PM
The wonders of HTTP. :D You'll have to do some parsing/cleaning of the SERVER vars. They won't always be giving you the exact output you expect.

11-15-2010, 04:37 PM
Thx for the reply,the echo seems ok, so isn't the problem in the href code?

$redirect = $_SESSION['comeback'];
echo $redirect;

11-15-2010, 04:39 PM
Make the URI absolute instead of relative.

$redirect = 'http://'.$_SESSION['comeback'];

It won't prepend the current path then.

11-15-2010, 04:54 PM
That did it Matt thanks:thumbsup: