This code should return all records in the property table if the array is empty and return selected records if there are items in the array.
I can get the array to be mounted and the database queried if I select at least one form item but I can not return all the values in the database if the array arrives empty. In fact it does not arrive empty, it arrives like this: [0] =>
and it is that part that gives error.
# Selecionando o tipo de imóvel
$tipo = $_POST['tipo'];
$tipo = (@explode('/', implode('/', $tipo)));
if (isset($tipo) && !empty($tipo)){
// se $tipo for um array e for maior que 0
if (is_array($tipo) && count($tipo) > 0) {
$where .= " CATEGORIA IN ('".implode("','", $tipo)."') AND ";
} else {
$where .= " CATEGORIA = '{$tipo}' AND ";
}
}
SQL without array items:
SELECT * FROM property WHERE 1 = 1 AND CATEGORY IN ('')
SQL with array items:
SELECT * FROM property WHERE 1 = 1 AND CATEGORY IN ('HOME')
Form
<input type="checkbox" name="tipo[]" value="CONJUNTOSALA/LOJA" id="tp5">
<label for="tp5">Conjunto/Sala/Loja</label>
<input type="checkbox" name="tipo[]" value="FLAT/LOFT" id="tp6">
<label for="tp6">Flat/Loft</label>
<input type="checkbox" name="tipo[]" value="PREDIO COMERCIAL" id="tp7">
<label for="tp7">Prédio Comercial</label>
<input type="checkbox" name="tipo[]" value="TERRENOS" id="tp8">
<label for="tp8">Terreno/Área</label>