Database not returning any value

-1

I have the following code:

 $sql="SELECT * FROM imoveis WHERE 
          (suite LIKE '%".$suites."%' 
           OR banheiro LIKE '%".$banheiro."%'
           OR quarto LIKE '%".$quarto."%' 
           OR garagem LIKE '%".$garagens."%')

           AND (motivo LIKE '%".$tipo1."%'  
           OR tipo LIKE '%".$tipo."%')
           AND cidade LIKE '%".$cidadd."%' 
           AND estado LIKE '%".$local."%' 
           AND preco >= '$valor' 
           AND tamanho <= '$tamanho' ";

        $anunciarRadio=mysqli_query($conexao,$sql);

What I need is for me to return to the houses in the same city as my variable as determined by the amount of garage, suites, bathrooms, approximate rooms, $ value , and size greater than the $ size variable.

What am I doing wrong?

By putting the exact same values as those saved in the database it does not return anything ... Is it syntax or logic error?

When I put everything to or he returns but all come. I need a fine comb, but not so much, I need not prioritize some fields like bedrooms, bathrooms, garage, suite and the rest prioritize as being accurate ...

    
asked by anonymous 11.12.2018 / 00:00

2 answers

0

This here

       AND preco >= '$valor' 
       AND tamanho <= '$tamanho' ";

Would not it be so?

       AND preco >= '" .$valor. "' 
       AND tamanho <= '" .$tamanho. "'";

Correcting your select: About BETWEEN: You can see better here

     $sql="SELECT * FROM imoveis WHERE 
      (suite BETWEEN ".($suites - 2)." AND ".($suites + 2)."
       OR banheiro BETWEEN ".($banheiro - 2)." AND ".($banheiro + 2)."
       OR quarto BETWEEN ".($quarto - 2)." AND ".($quarto + 2)." 
       OR garagem BETWEEN ".($garagens - 2)." AND ".($garagens + 2).")

       AND (motivo LIKE '%".$tipo1."%'  
       OR tipo LIKE '%".$tipo."%')
       AND cidade LIKE '%".$cidadd."%' 
       AND estado LIKE '%".$local."%' 
       AND preco >= '".$valor."' 
       AND tamanho <= '".$tamanho."' ";

So I understand that you want the garage number, suites, bathrooms, rooms to be close to what the user typed soon, this is to do this:

// supon que suites sejam 4
suite BETWEEN ".($suites - 2)." AND ".($suites + 2)."
// Nessa parte abaixo eu diminuo 2 para que ele procure apartir de 2  
".($suites - 2)." 
// ate 6. aqui eu aumento 2 para o valor ser 6
".($suites + 2)."

Summarizing the code will return if the property number is between 2 and 6. I hope it was clear and helped you now.

ps: no php handle so I'm not sure that .($suites - 2). is correct operation, but I think so because in the other languages are so one, hug. : D

    
11.12.2018 / 16:41
0

Is this variable the same?

AND cidade LIKE '%".$cidadd."%'

And the friend example @Will can be so tb.

AND preco >= '{$valor}' 
AND tamanho <= '{$tamanho}'";
    
11.12.2018 / 16:51