I need a way to search across dynamically generated fields. A user will search for 3 required fields and n number of optional fields.
This is for search functionality.
Said user might want to look for any issue that is on the West elevation (field_id->1, field_value->West), on the 6th Floor (field_id->4, field_value->6), and in room #52 (field_id->2, field_value-> 52).
Here is what I have so far:
$query = "SELECT inspection_finding_id
FROM if_field_values
WHERE field_id IN (1, 2, 4) AND field_value IN ('West', 6, 52)
GROUP BY field_id, field_value, inspection_finding_id";
$result = mysql_query($query);
I only need the id's that match ALL of the criteria... With the above I get some orphan records that are also contain data on the 6th floor.
I dont have enought rep to show an image of my table so here is a sad attempt to display my table
| id | field_id | field_value |
+----+----------+-------------+
|161 | 1 | West |
|161 | 4 | 6 |
|161 | 2 | 52 |
|163 | 4 | 6 |