0
I want to make a condition for when a value is selected, the condition is like this at the moment:
if (!empty($_GET['faixa_de_preco'])) {
$valor = $_GET['faixa_de_preco'];
if ($valor == 1) {
$result = "< 1000000.00";
}
if ($valor == 2) {
$result = ">= 1000000.00 AND price <= 2000000.00";
}
if ($valor == 3) {
$result = ">= 2000000.00 AND price <= 3000000.00";
}else{
$result = "";
}
$filter .= " AND price {$result}";
}
Here’s what happens when I add one more if
it ignores the top one. An example, in this code, when I select an option with the value 3, works that is the only one if
that works is the
if ($valor == 3) {
$result = ">= 2000000.00 AND price <= 3000000.00";
}
when I select an option with the value 1 or 2, it falls into the else
, and if I add one more if
, the if ($valor == 3)
begins to fall into the else
also.
The problem is your logic. Note that when $value == 1 (or 2) the way you did it will enter the
if ($valor == 3) {
and how theelse
. Utilizeelse
in all theif
. Also note that when $value is different from 1, 2 and 3 your filter will be wrong.– anonimo