search query needed
Posted: Fri May 16, 2008 1:27 am
Dear all,
I am making a search algo that will search the database upon provided inputs
There are 5 inputs
1.keywork :- which is textfield and name is keyword
2.course : which is a drop down and name is course
3.level : which is a drop down and name is level
4.country : which is a drop down and name is country
5.university : which is a drop down and name is university
when user inters anything in the keyword field then it shd search in the rest 2-5 field correspinding in the dabase base and if user inputed any string in the keyword field and chose anything from rest search parameters then is should refine the search accordingly.
what is happeneing with my code is when user inters anything in keyword field it is searing correct but when user inters anything in keyword and rest 4 field then it is not redefining search.
i am giving the code below
$selectors = array(
"keyword" => "tbluniv_degree like '%$_POST[keyword]%' or tbluniv_branch_name like '%$_POST[keyword]%' or tbluniv_country like '%$_POST[keyword]%' or tbluniv_level like '%$_POST[keyword]%' or tbluniv_uni_name like '%$_POST[keyword]%'",
"course" => "tbluniv_branch_name = '$_POST[course]'",
"country" => "tbluniv_country = '$_POST[country]'",
"level" => "tbluniv_level = '$_POST[level]'",
"university" => "tbluniv_uni_name like'%$_POST[university]%'"
);
$cwant = array();
foreach (array_keys($selectors) as $cdi) {
if ($_POST[$cdi]) {
array_push($cwant, $selectors[$cdi]);
}
}
if ($cwant) {
$restrict = implode (" and ",$cwant);
$choose = 1;
} else {
$choose = 0;
}
if($choose)
{
echo $sql="select distinct(university_username),tbluniv_id,tbluniv_uni_name ,tbluniv_degree,tbluniv_med_inst, tbluniv_beg_prog,tbluniv_prog_dur ,tbluniv_app_deadl from tbluniv_courses_detail WHERE $restrict";
$res=mysql_query($sql);
}
else
{
echo $sql="select distinct(university_username),tbluniv_id,tbluniv_uni_name ,tbluniv_degree,tbluniv_med_inst, tbluniv_beg_prog,tbluniv_prog_dur ,tbluniv_app_deadl from tbluniv_courses_detail WHERE 1=2";
$res=mysql_query($sql);
}
any help wll be apreciated
thanks and regards
jawed
I am making a search algo that will search the database upon provided inputs
There are 5 inputs
1.keywork :- which is textfield and name is keyword
2.course : which is a drop down and name is course
3.level : which is a drop down and name is level
4.country : which is a drop down and name is country
5.university : which is a drop down and name is university
when user inters anything in the keyword field then it shd search in the rest 2-5 field correspinding in the dabase base and if user inputed any string in the keyword field and chose anything from rest search parameters then is should refine the search accordingly.
what is happeneing with my code is when user inters anything in keyword field it is searing correct but when user inters anything in keyword and rest 4 field then it is not redefining search.
i am giving the code below
$selectors = array(
"keyword" => "tbluniv_degree like '%$_POST[keyword]%' or tbluniv_branch_name like '%$_POST[keyword]%' or tbluniv_country like '%$_POST[keyword]%' or tbluniv_level like '%$_POST[keyword]%' or tbluniv_uni_name like '%$_POST[keyword]%'",
"course" => "tbluniv_branch_name = '$_POST[course]'",
"country" => "tbluniv_country = '$_POST[country]'",
"level" => "tbluniv_level = '$_POST[level]'",
"university" => "tbluniv_uni_name like'%$_POST[university]%'"
);
$cwant = array();
foreach (array_keys($selectors) as $cdi) {
if ($_POST[$cdi]) {
array_push($cwant, $selectors[$cdi]);
}
}
if ($cwant) {
$restrict = implode (" and ",$cwant);
$choose = 1;
} else {
$choose = 0;
}
if($choose)
{
echo $sql="select distinct(university_username),tbluniv_id,tbluniv_uni_name ,tbluniv_degree,tbluniv_med_inst, tbluniv_beg_prog,tbluniv_prog_dur ,tbluniv_app_deadl from tbluniv_courses_detail WHERE $restrict";
$res=mysql_query($sql);
}
else
{
echo $sql="select distinct(university_username),tbluniv_id,tbluniv_uni_name ,tbluniv_degree,tbluniv_med_inst, tbluniv_beg_prog,tbluniv_prog_dur ,tbluniv_app_deadl from tbluniv_courses_detail WHERE 1=2";
$res=mysql_query($sql);
}
any help wll be apreciated
thanks and regards
jawed