php search help :p

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

php search help :p

Post 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?
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
User avatar
Foo
Posts: 13840
Joined: Thu Aug 03, 2000 7:00 am
Location: New Zealand

Post by Foo »

Which part of the problem, exactly?

Passing them across to the script or executing the search?

Can you give us the specifics?
"Maybe you have some bird ideas. Maybe that’s the best you can do."
― Terry A. Davis
4days
Posts: 5465
Joined: Tue Apr 16, 2002 7:00 am

Post 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';
Dave
Posts: 6986
Joined: Sat Jan 15, 2000 8:00 am

Post by Dave »

I just let google index my shit then I use a site:xxx.com query to search it
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post 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*
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
User avatar
Foo
Posts: 13840
Joined: Thu Aug 03, 2000 7:00 am
Location: New Zealand

Post by Foo »

If you detect 'device_id' or any of the other fields as being blank, just insert the wildcard character?
"Maybe you have some bird ideas. Maybe that’s the best you can do."
― Terry A. Davis
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post by dmmh »

got it working....god I love PHP
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Post Reply