Exists == or === in MYSQL

0

I have looked for the question, to see if something appears about it, but I think I have not seen it, if so, I apologize in advance.

The point is the following, I have a query in mysql where in theory I should show 2 values, otherwise, do not show anything.

In my database there are types of properties (apartments or apartments, houses, etc.) and types of operations (sale, rent, etc.).

I have a search engine on my database, where what I do is receive the information from my form and this should give me what I need.

For example if in my form $ type = 'apartment' and $ operation = 'sale', I should show only that, but the fact is that it shows me all the properties for sale, even if they are not apartments. This is the sentence:

$busqueda = $conexion->query("SELECT * FROM inmuebles WHERE operacion = '$operacion' AND tipo = '$tipo' ORDER BY precio_dolar ASC LIMIT 100");

I know that in PHP there is the operator == that would force the search to be exactly the same as the string that is being requested, my question is punctual, there is something similar in Mysql, because I have not found it in the manuals.

!!! APOLOGIZE the whole Community !!! but I already found my fault. It has nothing to do with the sentence, but with the way you code my script.

What happens is the following, I am trying to create a search engine where there are 8 options, in theory, these options are filters and should work, but what happens.

If you select 1 option only, it shows all the properties with that single option and so the options are added until the 8 selected options are completed.

What happened, this:

if(!empty($operacion)) {
  ##el codigo
}
elseif (!empty($operacion) AND !empty($tipo)) {
  ##3el codigo
}

In both cases $ operation is not an empty string "", therefore both sentences are going to be executed, but if you deleted the first if, the statement executes perfectly.

Forgive my ignorance,: - (

    
asked by Jean Carlo Garcia Quiñones 31.07.2018 в 20:08
source

1 answer

0

Try to first get the query with the parameters you submit and verify that everything is fine, then copy that query and run it in phpMyAdmin to rule out possible errors.

/* Las funciones print_r() y exit() las remueves una vez que obtengas la consulta. */

$q = "SELECT * FROM inmuebles WHERE operacion = '$operacion' AND tipo = '$tipo' ORDER BY precio_dolar ASC LIMIT 100";

print_r($q);
exit();

$busqueda = $conexion->query($q);
    
answered by 31.07.2018 в 20:28