iPixel Posted April 24, 2009 Share Posted April 24, 2009 Here's my SQL query "SELECT * FROM syx_ad WHERE firstname LIKE '%$q%' OR lastname LIKE '%$q%' AND status = 'Active' LIMIT 20" the LIKE's are satisfied but it doesnt bother checking for status.. results still display the user if his/hers status is Inactive... am i just doing something wrong? Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/ Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 seems right to me =/ make sure You have all your column names and stuff right. Maybe try setting Active to a variable name and checking if status='$active' or something Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/#findComment-818610 Share on other sites More sharing options...
iPixel Posted April 24, 2009 Author Share Posted April 24, 2009 Tried the variable way also... no dice, and yes all my column names are correct. **GRR** annoying lol. Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/#findComment-818612 Share on other sites More sharing options...
kickstart Posted April 24, 2009 Share Posted April 24, 2009 Hi Do you want:- "SELECT * FROM syx_ad WHERE firstname LIKE '%$q%' OR (lastname LIKE '%$q%' AND status = 'Active') LIMIT 20" or "SELECT * FROM syx_ad WHERE (firstname LIKE '%$q%' OR lastname LIKE '%$q%') AND status = 'Active' LIMIT 20" Default precedence it will do the AND first. However it is best to use brackets to make the logic more obvious when you next have to touch the code. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/#findComment-818624 Share on other sites More sharing options...
iPixel Posted April 24, 2009 Author Share Posted April 24, 2009 Here's the logic to what i want. Basically the search has to be %LIKE% either firstname or last name, that doesnt matter.. just status HAS TO BE ACTIVE "SELECT * FROM syx_ad WHERE status = '$stat' AND firstname LIKE '%$q%' OR status = '$stat' AND lastname LIKE '%$q%' AND status = '$stat' LIMIT 20" Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/#findComment-818627 Share on other sites More sharing options...
Mchl Posted April 24, 2009 Share Posted April 24, 2009 So you want status = '$stat' AND (firstname LIKE '%$q%' OR lastname LIKE '%$q%') Courtesy George Boole Quote Link to comment https://forums.phpfreaks.com/topic/155554-why-is-one-condition-being-omitted/#findComment-818635 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.