graham23s Posted June 18, 2010 Share Posted June 18, 2010 Hi Guys, With this query, i only want to bring back results where the "in_stock" enum == 'Y' but the way it is now it brings back the product whether it's in stock or not: Query: $qS2 = "SELECT * FROM `fcpv3_products` WHERE `product_name` LIKE '%$searchString%' OR `product_description` LIKE '%$searchString%' AND `in_stock`='Y' ORDER BY `id`"; Is the query wrong? it look right lol chweers for any help guys Graham Link to comment https://forums.phpfreaks.com/topic/205207-query-help/ Share on other sites More sharing options...
Psycho Posted June 18, 2010 Share Posted June 18, 2010 The problem is because you have three different criteria using an AND and an OR. The order of precedence on how those are processed is causing the issue. AND's are processed before OR's. http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html As the query is interpreted now it is pulling records where: `product_name` LIKE '%$searchString%' OR `product_description` LIKE '%$searchString%' AND `in_stock`='Y' You obviously want records where one of the first two conditions is true AND the last condition is true. So, you should use parens to force how the line is interpreted. SELECT * FROM `fcpv3_products` WHERE (`product_name` LIKE '%$searchString%' OR `product_description` LIKE '%$searchString%') AND `in_stock`='Y' ORDER BY `id` Link to comment https://forums.phpfreaks.com/topic/205207-query-help/#findComment-1074147 Share on other sites More sharing options...
graham23s Posted June 18, 2010 Author Share Posted June 18, 2010 Thanks mj, that was the problem thanks again mate Graham Link to comment https://forums.phpfreaks.com/topic/205207-query-help/#findComment-1074176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.