php search help :p
php search help :p
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]
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';
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';
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*
$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]
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]