robs99 Posted February 10, 2009 Share Posted February 10, 2009 Hello, i have a problem with a mysql query. this is my query: SELECT * FROM `posts` WHERE `bandname` LIKE '%something%' OR `title` LIKE '%something%' AND `deleted` = '' AND `approved_by` != '' ORDER BY `date` DESC , `id` DESC LIMIT 0 , 30 im trying to perform a search (my search parameter is 'something'). the results show up properly, but it ignores the rest of the query. deleted and unapproved posts still show up for some reason...any ideas? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/144589-solved-problem-with-simple-mysql-select-query/ Share on other sites More sharing options...
aschk Posted February 10, 2009 Share Posted February 10, 2009 What does your data actually look like? Surely 'deleted' should be a boolean field, and 'approved_by' a varchar? Quote Link to comment https://forums.phpfreaks.com/topic/144589-solved-problem-with-simple-mysql-select-query/#findComment-758814 Share on other sites More sharing options...
robs99 Posted February 10, 2009 Author Share Posted February 10, 2009 What does your data actually look like? Surely 'deleted' should be a boolean field, and 'approved_by' a varchar? both fields are varchars (deleted contains the name of the user who deleted it) Quote Link to comment https://forums.phpfreaks.com/topic/144589-solved-problem-with-simple-mysql-select-query/#findComment-758823 Share on other sites More sharing options...
aschk Posted February 10, 2009 Share Posted February 10, 2009 In which case it's to do with the order of precedence of the operators you're using. Try: SELECT * FROM `posts` WHERE (`bandname` LIKE '%something%' OR `title` LIKE '%something%') AND `deleted` = '' AND `approved_by` != '' ORDER BY `date` DESC , `id` DESC LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/144589-solved-problem-with-simple-mysql-select-query/#findComment-758836 Share on other sites More sharing options...
robs99 Posted February 10, 2009 Author Share Posted February 10, 2009 thanks that solved it Quote Link to comment https://forums.phpfreaks.com/topic/144589-solved-problem-with-simple-mysql-select-query/#findComment-759032 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.