0

I'm trying to do this kind of query, When i make the query by get, i want to display the results from the id, for example if i have this id in my GET =11;

I want to display all the products with the category_id = 11, even if they have another id in the concat format, I don't know how i can do this kind of query,

 $id = $_GET['id'];
 $sql = "SELECT * FROM `product` WHERE `product_category_id`='$id'";

My product_category_id contains the id's of the categories in CONCAT format:

product_category_id (type text)
11,30,29
Deimos
  • 269
  • 1
  • 6
  • 17
  • Try this: `WHERE product_category_id IN($id)` – Rahil Wazir Apr 04 '14 at 13:34
  • After read back, I don't understand because an identifier should be unique. If my first read was good it's a possible duplicate of [mysql where in](http://stackoverflow.com/questions/9736284/mysql-where-in). – Debflav Apr 04 '14 at 13:34

2 Answers2

1

The FIND_IN_SET MySQL function might be what you're looking for.

$sql = "SELECT * FROM `product` WHERE FIND_IN_SET('$id', `product_category_id`)";
Tom Griffin
  • 435
  • 4
  • 9
0

With a field like that, you will have to do something like this:

$sql = "SELECT *
        FROM product
        WHERE product_category_id LIKE '$id,%'
        OR product_category_id LIKE '%,$id,%'
        OR product_category_id LIKE '%,$id'";

In general, though, this will be a slow query.

Aioros
  • 4,373
  • 1
  • 18
  • 21