Re: Searching and storing results index in cookies or session variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, July 12, 2006 3:40 pm, Brian Anderson wrote:
> 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?

You are making a nightmare out of something that is very very simple. :-)

Just put the sorting and filtering and paging into the SQL queries,
and be done with it.

If your database is properly indexed, it will be "just as fast" as
this convoluted solution you are attempting to devise, and done in
about 3 lines of code instead of thousands.


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux