|
Posted by Hemanth on 10/14/05 22:10
Hello there,
A newbie question....any help is appreciated.
I'm trying to create a script that searches a few database tables based
on the search text and user search preferences. I created a PHP script
(search_form.php) that displays textbox, a search button and a
preferences link. The preferences link opens a popup (preferences.html)
and lists search categories (checkboxes - with search only in column1,
column2 etc. or ALL) and a select button. If the users specify the
preferences I call search_form.php with an "prefs[]" array as argument.
In search_form.php I invoke another script (search.php) - to display
search results - based on user preferences and search text entered.
My question is, how do I make the script remember these preferences and
search text (if user selects links like "Back to Search Results" or
"Back to new search" in other pages) till he closes the existing
window. I understand I can use PHP sessions to acheive this but I
couldn't seem to make it work (probably I'm doing something wrong).
===========================================================
I use the below code in each PHP script.
<?php
session_start();
header("Cache-control: private");
?>
Here's the code I use in "search_form.php"
$fields = $_GET["prefs"]; //prefs array from "preferences.html"
//If preferences are not set by user AND session variable fields not
set
if(!isset($_SESSION['fields']) && !isset($fields))
$_SESSION['fields'] = array("all"); // use default option "ALL"
else{
//If session variable fields not set
if(!isset($_SESSION['fields']))
$_SESSION['fields'] = $fields; //else assign user preferences.
}
print_r($_SESSION['fields']); //PRINT options
==============================================================
The problem is, whenever I call the "search_form.php" from a link (Back
to New search) in search results page, the PRINT statement always
displays "all" - the default option - I mean, the first if statement is
always true. What could be the mistake in my code?
TIA
Singamsetty.
Navigation:
[Reply to this message]
|