vendredi 8 novembre 2019

How can I keep appending && to conditional statements in PHP?

I am trying to filter data in PHP based on provided conditions. Here is an example using pseudo code:

if(isset($check_height)) {
   $condition = ($height > $lower_limit && $height < $max_limit);
}
if(isset($check_weight)) {
   $condition .= ($weight > $lower_wt_limit && $weight < $max_wt_limit);
}
if(isset($profession)) {
   $condition .= ($profession == $something);
}

Now, if I want to get result for everyone within a height limit and with a specific profession, I could combine the first and third conditions using my conditional &&.

If I am only looking for results within given weight limit, I will simply get the second condition.

Basically, I want to append conditions to filter out results as long as there are some set parameters. This way, I won't have to write all possible permutations and combinations for the conditionals.

Appending them using .= obviously won't work because they are not strings. Is there any other way of combining these conditions?

Let me know if I could not clarify anything properly. Thanks.

Aucun commentaire:

Enregistrer un commentaire