Im' working with a fully functional nesetd set system in PHP
I'm using it to build a simple menu structure with max depth = 2
Now I've added in the table an additional field to control the visibility state of every single menu item, in other words if it's active or not. My need is that If I deactivate a parent I want that the query doesn't return any of the childrens even if they are active.
This is the actual code for retrieve the whole menu tree
SELECT `nesty`.*,
(COUNT(`parent`.`id`) - (`sub_tree`.`depth` + 1)) AS `depth`
FROM `menus` AS `nesty`,
`menus` AS `parent`,
`menus` AS `sub_parent`,
(
SELECT `nesty`.`id`,
(COUNT(`parent`.`id`) - 1) AS `depth`
FROM `menus` AS `nesty`,
`menus` AS `parent`
WHERE `nesty`.`lft` BETWEEN `parent`.`lft` AND `parent`.`rgt`
AND `nesty`.`id` = 1
AND `nesty`.`tree_id` = 1
AND `parent`.`tree_id` = 1
GROUP BY `nesty`.`id`
ORDER BY `nesty`.`lft`
) AS `sub_tree`
WHERE `nesty`.`lft` BETWEEN `parent`.`lft` AND `parent`.`rgt`
AND `nesty`.`lft` BETWEEN `sub_parent`.`lft` AND `sub_parent`.`rgt`
AND `sub_parent`.`id` = `sub_tree`.`id`
AND `nesty`.`tree_id` = 1
AND `parent`.`tree_id` = 1
GROUP BY `nesty`.`id`
HAVING `depth` > 0
ORDER BY `nesty`.`lft`
So basically I want to add in the where clause
AND `nesty`.`visible` = 1
If I add that it's working wel as long the deactivate items are not parent of someone So I need that a menu item isn't returned if has the visible field equals 0 and/or if its parent has the visible field equals 0
thnx in advance