2
I have the following situation, the user can select the language level, as: Basic, Intermediate or Advanced and I have it in checkbox form.
I need to assemble a dynamic query according to the or options selected by the user, as an example, if the user chooses the Basic and Intermediate level options, how could I mount this query to perform the search? Can be one, two or all options.
An example of how I was doing this research, wrongly:
if ($NivelIngles != ""){
if ( $lcWhere <> "" ) {
$lcWhere.= " AND (`candidato`.NivelIngles = '$NivelIngles ')";
} else {
$lcWhere.= " WHERE (`candidato`.NivelIngles = '$NivelIngles ')";
}
}
The result before mounting my search is like this:
Array ( [0] => Basico [1] => Intermediario )
I hope you were able to explain my question
Hello Bacco, thank you so much for the excellent help, but I’m having a hard time adapting this query to the model I have here, because I’m concatenating options with WHERE and AND to then generate the query, can you give me more of this tip? The model I passed in the initial post.
– adventistapr
Just add the additional conditions like this, after the mentioned code:
$query .= $cola.' curso="alemao" '; $cola = ' AND '
and repeat for all additional clauses. The secret is in the$cola
which will be 'WHERE' or 'AND' automatically.– Bacco
It would be interesting a more concrete example of query, so I can see what you need, because when using OR and, it is important that they are grouped correctly with
( )
to give the desired effect.– Bacco
How can I pass you? By the comment the space is small and the question of AND and OR is what weighs most.
– adventistapr
Then I no longer know if it would be a case of a new question, or edit and add below the existing one. But you would have to be careful, because if you alter too much the essence of the original question, it harms the existing answers... If you feel that this is the case for a new question, it would be good to be very specific to explain the requirements and the problem with details, so you don’t run the risk of a certain answer not meeting you 100%.
– Bacco