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! Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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))"; Quote Link to comment 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! Quote Link to comment 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 >_< Quote Link to comment 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.