Error in Query Mysql

Asked

Viewed 57 times

0

I have a php page that needs to do a query in 3 fields in Mysql Database.

Campo Aprovado
Campo Reprovado
Campo Resolution

$select = mysql_query("select * from denuncia where (resolution is NOT NULL) 
AND status='aprovado' or status='reprovado'");

This Query only returns the Failed field, however I need to return everything with approved status, failed and the Resolution field is not null.

Where am I going wrong?

  • The error must be in the logical operators' precedence, try: "select * from denuncia where (resolution is NOT NULL) 
AND (status='aprovado' or status='reprovado)'"

  • I had already tried this way. Returns this error: Warning: mysql_fetch_assoc(): supplied argument is not a Valid Mysql result Resource in

  • What is passing as an argument for the mysql_fetch_assoc?

  • The select variable of this query : while($fetch = mysql_fetch_assoc($select)){

  • Try to run the function echo mysql_error(); after the line $select = mysql_query("...");.

  • Syntax error You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '' at line 1

  • Sorry, there is a syntax error in the query I suggested, the last quotation marks were outside the parentheses, correcting: select * from denuncia where (resolution is NOT NULL) AND (status='aprovado' or status='reprovado').

  • It worked. Thank you :)

Show 3 more comments

1 answer

0


Hello!

You should write your query as follows:

select * from denuncia where resolution IS NOT NULL AND (status='aprovado' OR status='reprovado')
  • That’s right. I just added as a suggestion from @Pantera 3 above, the parentheses in the Status tb fields. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.