Sql filter query

0

In the following query, the user has several filtering options, you can filter by name, title, area, headquarters the problem is that the name field is not filtering , nothing is returning instead with the other filters if you return results

$nombre=$_POST['nombre'];
$cargo=$_POST['cargo'];
$area=$_POST['area'];
$sede=$_POST['sede'];

$registro=mysqli_query($conexion,"SELECT
                                  nombre,
                                  apellidos,
                                  cargo,
                                  area,
                                  correocorporativo,
                                  extension 
                                  FROM  formulario
                                  WHERE estado='A' 
                                  AND   nombre
                                  LIKE  '%".$nombre."%'
                                  AND   area LIKE '%".$area."%'
                                  OR    cargo LIKE '%".$cargo."%'
                                  OR    sede LIKE '%".$sede."%'"
    
asked by DANIEL FELIPE LOPEZ VARGAS 14.05.2018 в 04:47
source

1 answer

0

It seems like something about the AND and the OR. Monitor the parentheses so that they filter according to the needs. I'm not sure exactly what you need but I mean something like this:

WHERE estado='A' 
AND   nombre
LIKE  '%".$nombre."%'
AND   (area LIKE '%".$area."%'
OR    cargo LIKE '%".$cargo."%'
OR    sede LIKE '%".$sede."%'")

I hope it helps you.

    
answered by 14.05.2018 в 13:17