• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using LIKE in SQL query with activerecord

#1
[eluser]mandril[/eluser]
Hi everyone, i have a problem with LIKE.. it seems to not be working properly...

Im developing an e-commerce and need to get the related products, for that reason the table product has a field called : tags.

Here is my method... that returns nothing, and if i remove the p1.id != p2.id it returns the product itself.. quite logic.

Code:
public function getRelatedProducts($idProd)
{

$query = $this->db->query("SELECT p1.id, p1.name FROM product p1, product p2 WHERE p1.id='".$idProd."'  AND p1.id != p2.id AND p1.tags LIKE p2.tags");

return $query;

}

Ok help me analyze step by step..

I need to grab the name and the id of the product so...

SELECT p1.id, p1.name seems fine

I need to compare a product with other products..

FROM product p1, product p2 seems fine

Now i need that one of the product is the one the customer is viewing .. that variable is $idProd

WHERE p1.id='".$idProd."' AND seems fine

I dont need to get the name of the product itself as a related product Tongue so..

p1.id != p2.id seems fine

I have to get similar tags.. so i use LIKE

AND p1.tags LIKE p2.tags is this working ?

a product has a tag like this: cellphone sony ericsson cam

and i put a similar tag to other product: cellphone motorola cam

AND I GET NO RESULT....

Thnx for your help Smile


Messages In This Thread
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 02:11 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 04:38 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 05:02 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 05:24 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 06:20 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 06:44 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 10:29 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.