urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
Without wanting to give a complete solution, something like this:
if(isset($_GET['advance_searching']) && !empty($_GET)){
$where = "";
if($_POST['search_remarks']!="") $s[] = "`process` = '" . mysql_real_escape_string($_POST['search_remarks']) . "'";
... (other fields)
if($_POST['age_one']!="") $s[] = "`age` >= " . intval($_POST['age_one']);
... (other age)
if(isset($s))$where = "WHERE " . implode(" AND ",$s);
... (concatentate query string)
}
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
When You are looking in four search fields in same column (PROCESS), then AND will not work. You need to implode with OR. Same is applicable to AGE field. Separate age1, age2 with OR
Another thing I would like to mention there is no need to keep 4 fields. you can keep one field for one column, ultimately you are using PROCESS and AGE column so you need only 2 search fields not 6.
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
if(isset($_GET['advance_searching']) && !empty($_GET))
{
$where = " 1 = 1 ";
if($_POST['search_remarks']!="") {
$s[] = "`remarks` like '%" . mysql_real_escape_string($_POST['search_remarks']) . "%'";
}
if($_POST['search_industry']!="") {
$s[] = "`industry` like '%" . mysql_real_escape_string($_POST['search_industry']) . "%'";
}
if($_POST['search_position']!="") {
$s[] = "`position` like '%" . mysql_real_escape_string($_POST['search_position']) . "%'";
}
if($_POST['search_location']!="") {
$s[] = "`location` like '%" . mysql_real_escape_string($_POST['search_location']) . "%'";
}
if($_POST['age_one']!="" && $_POST['age_two']!="") {
$s[] = "(`age` between " . intval($_POST['age_one']) ." AND ".intval($_POST['age_two']) .")";
}
if(isset($s)){
$where = "WHERE (" . implode(" AND ",$s).")";
}
}
$query_str = "SELECT * FROM resumevault {$where}";
echo $query_str;
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
YOU can remove it and make it to
$where="";
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270