Jump to content

[SOLVED] Helpdesk/Reported users WHERE clause


burtybob

Recommended Posts

I have:

$sql=mysql_query("SELECT * FROM report WHERE (`verdict` = '') AND (`staff1` = '') OR (`staff2` = '') OR (`staff3` = '') AND (`staff1` != 'Adminben')  ORDER BY `dtreported` ASC");

And BTW satff1 is = Adminben and yet it still selects and show it!!!

Does anyone have any idea why this is i have tried also using a variable in their so as to automate it but to the same result.

Many thanks in advance.

 

the logic makes sense, but i "think" you mean todo this

$sql=mysql_query("SELECT * FROM report WHERE (`verdict` = '') AND ((`staff1` = '') OR (`staff2` = '') OR (`staff3` = '')) AND (`staff1` != 'Adminben') ORDER BY `dtreported` ASC");

yes, your OR's and AND's are confused. MySQL takes the quickest literal way out. you'll need to wrap up some conditions. The ONLY conditions that have to be met to match this statement is if staff2 = '' OR staff3 = ''. That's probably what you're getting; all cases where staff2 = '' OR staff3 = ''

 

$sql=mysql_query("SELECT * FROM report WHERE (`verdict` = '') AND (`staff1` = '') OR (`staff2` = '') OR (`staff3` = '') AND (`staff1` != 'Adminben')  ORDER BY `dtreported` ASC");

 

$sql=mysql_query("SELECT * FROM report WHERE (`verdict` = '') AND ((`staff1` = '') OR (`staff2` = '') OR (`staff3` = '')) AND (`staff1` != 'Adminben') ORDER BY `dtreported` ASC");

WORKS however

$sql=mysql_query("SELECT * FROM report WHERE (`verdict` = '') AND ((`staff1` = '') OR (`staff2` = '') OR (`staff3` = '')) AND ((`staff1` != 'Adminben') OR (`staff2` !='Adminben')) ORDER BY `dtreported` ASC");

DOESNT.

 

Again Both staff1 and staff2 are set but when i check just staff1 it works but as soon as i try that staff2 using the  ( ) Double bracket method it breaks and just shows all of them even if if staff1 != Adminben.

 

Sorry to ask AGAIN but please does any one know why this is happening???

 

Many thanks in advance!

can you describe what your trying to get..

as your logic is wrong, so without know what you want is very hard to correct..!

 

a bit of a shot in the dark.. but

i think your searching for records where

verdict is empty, and staff1, 2 or 3 are empty

BUT Staff1 or 2  are set to Adminben,

 

so if staff1 is empty but staff2 is Adminben then ignore it..

 

something like

$sql=mysql_query("
SELECT * FROM report WHERE `verdict` = '' AND (`staff1` = '' OR `staff2` = '' OR staff3` = '') AND NOT (`staff1` = 'Adminben' OR `staff2` ='Adminben') ORDER BY `dtreported` ASC");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.