Page 1 of 1

php search help :p

Posted: Sat Aug 06, 2005 11:52 am
by dmmh
I'm trying to write an advanced filter function. Sofar I have 5 parameters which could lead to 25 possible queries. Instead of having to write them all, how do people normally tackle this problem?

Posted: Sat Aug 06, 2005 11:55 am
by Foo
Which part of the problem, exactly?

Passing them across to the script or executing the search?

Can you give us the specifics?

Posted: Sat Aug 06, 2005 12:03 pm
by 4days
without seeing how you're doing it, it's difficult to say. the main thing is making sure that your data is in a form that allows decent searches to be performed easily - and if you're expecting the search to be used a lot, make sure the tables it hits are indexed properly.

mostly, searches in php work by building up the components of a mysql query in strings, then lumping them all together and running the query.

crap e.g:

$query = 'SELECT * FROM asian_movies WHERE genre';

if($_POST['include_swords']) $querypart1 'AND include_swords = 1';
if($_POST['has_plot']) $querypart2 = 'AND has_plot = 1';
if($_POST['has_white_bad_guy']) $querypart3 = 'AND has_white_bad_guy = 1';

Posted: Sat Aug 06, 2005 12:10 pm
by Dave
I just let google index my shit then I use a site:xxx.com query to search it

Posted: Sat Aug 06, 2005 12:21 pm
by dmmh
nm..silly me...I like your solution 4days

$device_id = mysql_real_escape_string($_GET['device_id']);
$operator_id = mysql_real_escape_string($_GET['operator_id']);
$country_id = mysql_real_escape_string($_GET['country_id']);
$language_id = mysql_real_escape_string($_GET['language_id']);
$category_id = mysql_real_escape_string($_GET['category_id']);

$query = 'SELECT * FROM files'.
" INNER JOIN selectors_predefined".
" ON selectors_predefined.id = files.device_id".
" WHERE device_id = '$device_id'";

now, people may use any of those 5 variables in a form, or just use 1
the first 4 will only hold one, but the $category_id may even be an array of id's

*crunch crunch*

Posted: Sat Aug 06, 2005 12:27 pm
by Foo
If you detect 'device_id' or any of the other fields as being blank, just insert the wildcard character?

Posted: Sat Aug 06, 2005 12:36 pm
by dmmh
got it working....god I love PHP