Answer the question
In order to leave comments, you need to log in
How to organize a multiple OR query with a dynamic number of conditions?
There is a search, in it the user can add a number of conditions and I need to display the database in accordance with what he has chosen. For example, he chose 3 checkboxes and I have to select in the database:
... OR checkbox1=value1 OR checkbox2=value2 OR checkbox3=value3 ...
if (условие)
lot of code comes out through and if there are 20+ points, then in general it is not realistic to describe all combinations of checkboxes. How to do it right?
Answer the question
In order to leave comments, you need to log in
sequentially check the items in the loop, write the conditions to the array, at the end combine it into a string and collect the request.
If points > 2 then:
$InString = '';
foreach ($_POST["checkbox"] as &$value) {
$value = intval($value);
$InString .= $value.",";
}
$InString = preg_replace('/,$/ism', '', $InString);
SELECT FROM `indexation_job` WHERE id IN ('.$InString.')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question