Passing vars to next page of result display
Posted: Sun Jan 04, 2004 11:03 am
Project: user selects various criteria for a search, and results display limited to first 20 of howevermany. There is a "Next" and "Previous" link to step through the remaining results. I am trying to maintain the search criteria, so that the results maintain consistancy.
What I was trying was to place the $_POST vars into a temp array and saving that in $_SESSION. IT seems to work for the most part, but losses the "$key" name, and just uses a numeric key instead. I'm still new at associative arrays and thought someone could guide me through this.
Sample code follows:
How do I keep the key name while saving into session??

[Edit: Added PHP & CODE tags for eyecandy. --JAM]
What I was trying was to place the $_POST vars into a temp array and saving that in $_SESSION. IT seems to work for the most part, but losses the "$key" name, and just uses a numeric key instead. I'm still new at associative arrays and thought someone could guide me through this.
Sample code follows:
Code: Select all
if($_POST['doCommand']) {
// form was submitted
$varArray=array(); // set up temp array
foreach($_POST as $key=>$value) { // read in each posted var
$tempArray = array("$key"=>"$value");
$varArray = array_merge ($varArray, $tempArray);
}
$_SESSION['hold_vars']=$varArray; // save to session
while(list($key,$value) = each ($varArray)) {
echo("$key:$value<br>"); // this displays correctly
}
} else {
// form was not submitted
$varArray=$_SESSION['hold_vars']; // recover temp vars
while(list($key,$value) = each ($varArray)) {
echo("$key:$value<br>"); // this displays number keys
}
}Code: Select all
===
1st time displays:
citySearch:Livermore
min_price:275
max_price:325
beds:3
baths:2
doCommand:submit
===
2nd time displays:
0:Livermore
1:275
2:325
3:
4:
5:[Edit: Added PHP & CODE tags for eyecandy. --JAM]