Forum Moderators: coopster

Message Too Old, No Replies

Saving search criteria for the user

Is this the best approach?

         

HeadBut

4:08 pm on Sep 8, 2005 (gmt 0)

10+ Year Member



I’d like to save my users search results so they do not have to build them over and over. My idea is to make a mysql table with userid, search name, searchcriteria to save their searches.
Then I will take the standard search sql like:

$NewQuery = “SELECT * FROM SearchTable WHERE ”

Then Add their search:
$UserQuery = “1 = 1”;

If(!empty($_Post[‘colour’])){ /* repeat this for each Postable item */
$UserQuery.= “ AND colour = “.stripslashes($_Post[‘colour’]);
}

After all their search criteria:
$NewQuery .= $UserQuery;

Then save their $UserQuery to a $_Session var and allow them to save it if they want.

And of course finish with the standard:

$NewQuery .= “LIMIT “.$Page.”, “.$PerPage.” “;

$NewQueryresult = mysql_query($NewQuery, $connect) or die ("query 1: " . mysql_error());

I hope this is understandable!
If someone has a different approach I’d really like some input.

Thanks

mcavic

5:29 pm on Sep 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure about your code -- but yes, the best approach is to store their preferences in the database, then use a cookie to tie the database to their browser.

I don't know if there's a mechanism that will automagically handle *persistent* cookies, so you may have to code the cookie handling yourself with setcookie() and $_COOKIE[].