I'm trying to create a PHP script to filter data from a MySQL DB. Filters are selected with HTML Select tags.
The problem is, there are many filters, and a user may only select some of them. I'm quite confused about how to use PHP to dynamically adjust the MySQL select statement so that it only uses those filters selected by the user. That is, if the user select SchoolType and District. The query is something like this:
"SELECT * FROM mydatabase
WHERE SchoolType='SelectedSchoolType'
AND District='SelectedDistrict'"
And then if the user also select County in the filter, the SQL statement adjusts to:
"SELECT * FROM mydatabase
WHERE SchoolType='SelectedSchoolType'
AND District='SelectedDistrict'
AND County='SelectedCounty'"
How can I make the SQL statement adjust according to the filter selected?