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:
$childCategoryID = 55
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