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 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? 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) 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 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 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
Archived
This topic is now archived and is closed to further replies.