> > $query = > "SELECT * > FROM $table "; > if($source != "All") $query .= "and source = '".$source."'"; > if($hardware != "Both") $query .= "and hardware = '".$hardware."'"; > if($plant != "All") $query .= "and plant = '".$plant."'"; > if($area != "All") $query .= "and area = '".$area."'"; -------------------------
Hi. The problem here is that theres no WHERE nowhere in the sentence, and there's nowhere space in the "$query .=" lines If all criterias are true you would get something like this: SELECT * FROM $table and source = 'something'and hardware = 'something'and plant = 'something'and area = 'something' The code that would work looks like this: $query = "SELECT * FROM $table "; if($source != "All" || $hardware != "Both" || $plant != "All" || $area != "All") $query .= "WHERE "; if($source != "All") $query .= " source = '".$source."' "; if($source != "All" && $hardware != "Both") $query .= " and "; if($hardware != "Both") $query .= " hardware = '".$hardware."' "; if(($source != "All" || $hardware != "Both") && $plant != "All") $query .= " and "; if($plant != "All") $query .= " plant = '".$plant."' "; if(($source != "All" || $hardware != "Both" || $plant != "All") && $area != "All") $query .= " and "; if($area != "All") $query .= " area = '".$area."' "; Or something like this...
