решение на sql
SELECT `c`.`id` as idpar1,`c`.`name` as parent1name,`c`.`parent` as parent1,`c2`.`id` as idpar2,`c2`.`name` as parent2name,`c2`.`parent` as parent2, `c3`.`id`,`c3`.`name` as name,`c3`.`parent`
FROM `categories` `c` JOIN `categories` `c2` ON `c2`.`parent`=`c`.`id` JOIN `categories` `c3` ON `c3`.`parent`=`c2`.`id`
WHERE `c3`.`name` LIKE '%Лод%' LIMIT 50