I have a problem, I wanted to make a query to the search form data where people insert some filters will search for products appear less in this specific case are houses. had made a query with "or" does not work as well as this it makes the fields alone, and "and" not also works because I do not want users to fill out all the fields, so is the they want, so I did it
$texto = array();
$contador=0;
if($_SESSION["finalidade"]!=""){
$contador++;
$texto[1]="`finalidade` LIKE ".$finalidade;}
if($_SESSION["tipoimovel"]!=""){
$contador++;
$texto[2]="`tipoimovel` LIKE ".$tipoimovel;}
if($_SESSION["nquarto"]!=0){
$contador++;
$texto[3]="`nquartos` = ".$nquarto;}
if($_SESSION["pmin"]!=0){
$contador++;
$texto[4]="`preco` > ".$pmin;}
if($_SESSION["pmax"]!=0){
$contador++;
$texto[5]="`preco` < ".$pmax;}
if($_SESSION["elevador"]!=""){
$contador++;
$texto[6]="`elevador` LIKE ".$elevador;}
if($_SESSION["garagem"]!=""){
$contador++;
$texto[7]="`garagem` LIKE ".$garagem;}
if($_SESSION["vistapriv"]!=""){
$contador++;
$texto[8]="`vistapreveligiada` LIKE ".$vistapriv;}
if($_SESSION["piscina"]!=""){
$contador++;
$texto[9]="`piscina` LIKE ".$piscina;}
if($_SESSION["jardim"]!=""){
$contador++;
$texto[10]="`jardim` LIKE ".$jardim;}
if($_SESSION["condominiof"]!=""){
$contador++;
$texto[11]="`condominio` LIKE ".$condominiof;}
if($_SESSION["conselho"]!=""){
$contador++;
$texto[12]="`conselho` LIKE ".$conselho;}
if($_SESSION["frequesia"]!=""){
$contador++;
$texto[13]="`frequesia` LIKE ".$frequesia;}
if($_SESSION["refimovel"]!=""){
$contador++;
$texto[14]="`referencia` LIKE ".$refimovel;}
$textocompleto="";
$contador2=1;
for($y = 0; $y < 16; $y++) {
if($texto[$y]!=""){
if($contador2==1 && $contador2!=$contador){
$contador2++;
;
$textocompleto=$texto[$y]." AND "; }
elseif($contador2==$contador){
$contador2++;
$textocompleto=$textocompleto.$texto[$y];}
elseif($contador2==1 && $contador2==$contador){
$contador2++;
$textocompleto=$texto[$y]; }
else {
$contador2++;
$textocompleto=$textocompleto.$texto[$y]." AND ";}
}
}
$results = $mysqli->prepare("SELECT ID, imagem, frequesia ,conselho, preco FROM `imovel` WHERE ? ORDER BY `imovel`.`preco` DESC LIMIT ?,? ");
$results->bind_param("sii",$textocompleto, $page_position, $item_per_page);
$results->execute();
$results->bind_result($id ,$imagem, $frequesia ,$conselho, $preco); //bind variables to prepared statement
}
the problem is that it is not me to return anything, does not show me any value. already do not know what else to do because if you make a if for each of the possibilities will give more than 100 if and will take a long time. if anyone knows of some effective and quick way to do this please help me, because in fact not know what else to do to fix this problem, thank you