0
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 I need you to return to the houses in the same city as my variable with determined with the amount values of garage, suites, bathrooms, approximate rooms, with variable lower price value $value, and larger than variable size $size.
What am I doing wrong??
By putting the values exactly equal to those recorded in the database it does not return me anything... sera is a syntax or logic error ?
When I put everything to him, he returns but everyone comes. In other words, it takes a fine comb, but not so much, I need to prioritize some fields as bedrooms, bathrooms, garage, suite and the rest prioritize as being exact...
I made that correction and still nothing comes. , I believe it is related to AND and OR @.@ was studying the use of them but I did not understand correctly, how to use in the way described above with quotation marks can leave some fields as not so necessary and others as being obligatory igua, however may have grammatical errors
– Elizandro Schmidt
Well I’ll try to pass it to you quickly, AND you use when you want the returned value to be what the comparison variable contains if it does not contain it will not return, if in your code if the 'immovable' you are looking for in select has all variables equal to the comparison or in the case of 'AND var like %something%' the value 'var' is contained inside 'something' it will return oimovel, now if any variable of the comparison AND returns false, ie does not contain, your select will not return anything.
– Will
Note that I did not mention the OR because the OR is simpler if it finds the value it returns but if it does not find the corresponding value it will not return if it is comparing alone. Example "select * from immovables Where 1 = 0 OR name like '%nameImovel%' " Here Where 1=0 is so forever to be 0(false) or if OR is 1 it returns and is 0 it returns nothing. In the case of select if only the OR is true it will not return and if only the OR is false and the AND are true it will return
– Will
Summarizing AND will only return when all conditions are True. OR will return when any of the conditions are met.
– Will
I updated my answer see if it can now be of help.
– Will
It worked thank you.. that’s what was in doubt.. Perfect congratulations thank you.
– Elizandro Schmidt
I’m happy to help :D
– Will