Jump to content

Using LIKE statement but excluding rows


melting_dog

Recommended Posts

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.