Searching and storing results index in cookies or session variables

From: Date: Wed, 12 Jul 2006 20:40:19 +0000
Subject: Searching and storing results index in cookies or session variables
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-239371@lists.php.net to get a copy of this message
Hello, I have a question about how I am searching through a products database. What I am wanting to do is store the result set so that I can provide a link to go back to previous searches quickly, and also manipulate it quickly. If I had a flat catalog of pages I could index the content in a few tables and go with that, but I want the results to be customizable, and more flexible than ten links to ten items on ten different pages. I want the results delivered and recombined in one page. Currently what I am doing is the following: 1. I open an SQL statement with delimiters 2. I circulate through the entries and append to a array called
    $pageset both the item number and a ranking based on keywords etc.
3. I sort the array by relevance ranking 4. I figure out what my limit and offset are in my array and paginate
    based on user input.
5. I grab the 20 or so array elements within the range and create a
    new array called $display set.
6. For each of the current page items I pull the full item details
    from the database and propagate the array to my html template
I wonder if instead of propagating the $pageset (results index) array every time I could store the $pageset array as a cookie or session variable. It is a small array with a few hundred elements and rankings, but if I could store it, I wouldn't have to build the array and do a relevancy sort every time I paginate to the next page. I would just take the current stored search array which is already sorted, and grab element x through element y. Would this be an efficient way using a session variable? Does anybody else handle search results in a similar way? -Brian Anderson

« previous php.general (#239371) next »