melting_dog Posted January 9, 2012 Share Posted January 9, 2012 Hi all, I have a site that displays a product, then shows similar products based off the name of the first (like a 'You might also like...' list). However the original product keeps appearing in this similar product list. I need a way to exclude that product. You can see this here: http://adamsherman.com.au/postureperfection/product-page/?prodid=3 Notice how the Reno Stool also appears in the suggested items list. Can anyone help me out? Heres the SQL: $sql = "SELECT * FROM product WHERE " . implode(' OR ', $searchTerms) . " AND product_id != '$prodid' LIMIT 3"; The .implode() just splits up the name of the item whilst $prodid is the items unique identifier. I have also tried NOT LIKE, <> and != $productname as well. Any help would be much appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/ Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 could you do a print_r($sql) and post up what you get from it please. Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/#findComment-1305724 Share on other sites More sharing options...
melting_dog Posted January 9, 2012 Author Share Posted January 9, 2012 Hi Muddy, This is what I get: SELECT * FROM product WHERE name LIKE '%Reno%' OR name LIKE '%Stool%' AND product_id != '3' LIMIT 3 Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/#findComment-1305726 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 I think it's an order problem, lets fling in some brackets and see what happens: $sql = "SELECT * FROM product WHERE ((" . implode(' OR ', $searchTerms) . ") AND (product_id != '$prodid' LIMIT 3))"; Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/#findComment-1305729 Share on other sites More sharing options...
melting_dog Posted January 9, 2012 Author Share Posted January 9, 2012 Hi Muddy, Thanks - I was able to do it by modifying your statement a bit: $sql = "SELECT * FROM product WHERE (" . implode(' OR ', $searchTerms) . ") AND product_id != '$prodid' LIMIT 3"; Works like a charm! Thanks! Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/#findComment-1305730 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 Glad you got it working, I see the problem in the code I gave you was that I included the LIMIT statment inside the brackets aswell >_< Link to comment https://forums.phpfreaks.com/topic/254642-using-like-statement-but-excluding-rows/#findComment-1305754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.