I am creating a query that depends on several input form values, and at some point I am working on three values. The first value queried has to be always 0, so I have this:
.. AND value_1 = 0
What I want to be able to do cleanly is the following:
If checkbox_2 is checked:
... AND (value_1 = 0 OR value_2 = 0)
If checkbox_3 is checked
... AND (value_1 = 0 OR value_3 = 0)
If checkbox_2 and checkbox_3 are checked
... AND (value_1 = 0 OR value_2 = 0 OR value_3 = 0)
I am creating the SQL query in a string, and I am wondering what would be a clean way to do this.
The cleanest way is to create an array filled with the options used in your SQL query and either
implodethe string together.Just make sure you hook up your check-boxes to the
$optionsarray.