I want to search data using ajax method with multiple fields search option (e.g. name, college, department, year, nationality e.t.c ). I have insert name for searching and rest of fields are empty than it went to foreach loop but this if (isset($_GET[$field]) && !empty($_GET['$field'])) condition not successful and went to else loop
$fields = array(
'name' => TRUE,
'gender' => TRUE,
'colf' => TRUE,
'deptf' => TRUE,
'natf' => TRUE,
'fstatusf' => TRUE,
'fyearf' => TRUE
);
foreach ($fields as $field => $like) {
if (isset($_GET[$field]) && !empty($_GET['$field'])) {
$value = $_GET[$field];
$search[] = $field . ( $like ? ('LIKE "%' . $value . '%"') : ('="' . $value . '"') );
}
}
if ($search) {
$sql = 'SELECT * FROM fmaf WHERE ' . implode(' or ' . $search);
}
else{
$sql="SELECT * FROM fmaf";
}