Incorrect filtering in a MYSQL Conlsulta

0

How about, I'm developing a system where I have a database filter.

I have the database with a field called "state" where I store 4 different data that are (Pending, Active, Completed, Does not Proceed)

others called "depto1" and another called "depto2" where I store the different types of Headquarters that exist in the company

I need to filter the data where it shows all the fields equal to the "status" that are in "depto1 or depto2"

This is my query: But it is mixing an erroneous data that does not equal the variable "state"

$query = "SELECT * FROM solicitudes 
          WHERE estado = '$filtro' 
                and depto1 = '".$usu."' 
                OR depto2 = '".$usu."' 
          ORDER BY folio DESC";

What am I doing wrong?

    
asked by Sharly Infinitywars 05.04.2017 в 04:43
source

1 answer

2

Hello what is happening, is that you have to group the OR within parentisis, so that your WHERE is left: state and the two departments. Here I pass the code:

$query = "SELECT * FROM solicitudes WHERE estado = '".$filtro."' AND (depto1 = '".$usu."' OR depto2 = '".$usu."') ORDER BY folio DESC"
    
answered by 05.04.2017 / 04:53
source