...

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



okeddy
11-14-2010, 02: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_connect("localhost","root","");

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`";

$result=mysql_query($query);
$num=mysql_num_rows($result);

mysql_close();

okeddy
11-14-2010, 05: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?

MattF
11-14-2010, 07:09 PM
Use sessions.

okeddy
11-14-2010, 08: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


<?php
session_start();
$_SESSION =$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
?>
<?php
echo "http://" .$_SESSION;
?>

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

db page

session_start();
$_SESSION['comeback'] = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

select page


session_start();
$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?

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


session_start();
$redirect = $_SESSION['comeback'];

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

http://127.0.0.1/127.0.0.1/indexfull2.php?Submit=Search&a=beatles&b=&c=&d=&e=&f=&g=&h=

MattF
11-15-2010, 02: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.

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


session_start();
$redirect = $_SESSION['comeback'];
echo $redirect;
outputs
127.0.0.1/indexfull2.php?Submit=Search&a=beatles&b=&c=&d=&e=&f=&g=&h=

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



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


It won't prepend the current path then.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum