PDA

View Full Version : Display Search Words on Results Page using Session Variable


dlovas275157
03-29-2011, 12:39 PM
I have a search page and a results page created using DataAssist Search Wizard. I would like to add to the top of the results page the following:

There are "145" Results for "keyword here"

The number of results is not a problem, but I cannot get the keywords to display properly.

I have set a session variable when the search form is submitted and named it "searchFieldValueMobi", then I try to display that session variable on the results page.

It seems to show the previously searched term instead of the currently searched term.

What am I doing wrong? Is this the best approach to handle this (session variable)? I chose session variable since pagination on the results page made it had to pass url variables from page to page. (using tom-mucks pagination extension)

Attached is my search/results page code.
Live link:
http://67.199.72.174/WM/mobi/searchPOST.php

Not sure if this is best posted in the "Cookies Toolkit Forum" or the "DataAssist Forum"

Jason Byrnes
03-29-2011, 12:44 PM
all for processing MUST happen on the forms action page.


this code on the search page:
<?php
if (!session_id()) session_start();
if (isset($_POST["searchSubmit"])) {
$_SESSION["searchFieldValueMobi"] = "".((isset($_POST["searchField"]))?$_POST["searchField"]:"") ."";
}?>

will not do anything since the form posts to the results page.

you need to out that code on the results page.

dlovas275157
03-29-2011, 01:06 PM
Jason,

I have revised my code. My issue now is the following:

The session is set on the results page as follows:
Trigger: before page load
Session Name: searchFieldValueMobi
Value: <?php echo $_POST['searchField']; ?>

If I search for "a" it brings back 42 pages of results and displays properly: "a" resulted in 42 pages

But, as soon as I click one of the page numbers, it wipes out the session variable since it is looking to load in the $_POST['searchField'] before page load which is now empty.

Is there any way to get around this?

attached code is revised
Live link has been updated as well: http://67.199.72.174/WM/mobi/searchPOST.php

Jason Byrnes
03-29-2011, 01:12 PM
set the trigger for the set session value behavior to use any form post instead of before page load.

dlovas275157
03-29-2011, 01:21 PM
Yes, that worked!! Thank you for your patience (and quick response) as I get better dealing with and understanding sessions.

- Daniel

Jason Byrnes
03-30-2011, 08:24 AM
you're welcome.