我在 PHP 中使用功能齐全的嵌套集系统
我正在使用它来构建一个最大深度 = 2 的简单菜单结构
现在我在表格中添加了一个额外的字段来控制每个菜单项的可见性状态,换句话说,它是否处于活动状态。我的需要是,如果我停用父母,我希望查询不会返回任何孩子,即使他们处于活动状态。
这是检索整个菜单树的实际代码
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`
所以基本上我想在where子句中添加
AND `nesty`.`visible` = 1
如果我补充说,只要停用项目不是某人的父项,它就可以正常工作所以我需要如果可见字段等于 0 和/或其父项的可见字段等于 0,则不返回菜单项
提前谢谢