// loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(isset($_GET[$field]) && !empty($_GET[$field])) {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "$field LIKE '%" . mysqli_real_escape_string($co, $_GET[$field]) . "%'";
}
}

// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= " AND " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
}}