Finding all parent categories in MYSQL
In this tutorial We have share how to get all parent categories from child category with a single query in MYSQL
I do this:
1 |
$childCategoryID = 55 |
1 2 3 4 5 6 7 8 9 10 11 |
SELECT c.* FROM ( SELECT @r AS _id, (SELECT @r := parent_id FROM category WHERE id = _id) AS parent_id, @l := @l + 1 AS level FROM (SELECT @r := ".$childCategoryID.", @l := 0) vars, category m WHERE @r <> 0) d JOIN category c ON d._id = c.id |