burtybob Posted October 17, 2007 Share Posted October 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/ Share on other sites More sharing options...
MadTechie Posted October 17, 2007 Share Posted October 17, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-371767 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-371769 Share on other sites More sharing options...
burtybob Posted October 17, 2007 Author Share Posted October 17, 2007 Thank you very much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-371775 Share on other sites More sharing options...
burtybob Posted October 17, 2007 Author Share Posted October 17, 2007 $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! Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-371789 Share on other sites More sharing options...
MadTechie Posted October 17, 2007 Share Posted October 17, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-371890 Share on other sites More sharing options...
burtybob Posted October 19, 2007 Author Share Posted October 19, 2007 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, Almost right but where satff 1 or 2 is NOT set to adminben/the players name. Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-373322 Share on other sites More sharing options...
MadTechie Posted October 19, 2007 Share Posted October 19, 2007 i think this may work.. $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"); Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-373482 Share on other sites More sharing options...
burtybob Posted October 21, 2007 Author Share Posted October 21, 2007 Thank you this did work after i corrected one minor probelm with your code it was missing a ` but everything else was right so thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/73686-solved-helpdeskreported-users-where-clause/#findComment-374763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.