邻接列表模型按路径选择

发布于 2024-09-07 05:01:16 字数 512 浏览 1 评论 0原文

我正在尝试在我的层次结构系统中选择一个节点。

我有“/Path/To/Some/Node”(正是这种形式),我试图弄清楚如何获得“Node”的子节点。当然,“Node”是伪唯一的,因为它是 Some 内唯一名为“Node”的子节点,但“Path”内可能还有另一个“Node”,所以你显然不能只是爆炸,然后做一个简单的操作节点。

所以我需要创建一个选择查询来查看每个级别...

我显然可以通过使用大量查询来做到这一点,即。

Select id from Table where name = "Path"
Select id from Table where name = "To" and parent = "$id"
Select id from Table where name = "Some" and parent = "$id"
Select id from Table where name = "Node" and parent = "$id"

这并不理想... 有人可以建议吗?

I'm trying to select a node in my heirarchical system.

I have the "/Path/To/Some/Node" (In exactly that form) and I am trying to figure out how I can get the children of "Node". Naturally "Node" is pseudo-unique, in that it is the only child called "Node" inside of Some, but there could be another "Node" inside of "Path" so you obviously can't just explode and then do a simple Node.

So I need to create a select query which looks down each level...

I could obviously do this by using tonnes of querys, ie.

Select id from Table where name = "Path"
Select id from Table where name = "To" and parent = "$id"
Select id from Table where name = "Some" and parent = "$id"
Select id from Table where name = "Node" and parent = "$id"

This isn't ideal...
Can anyone advise?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-09-14 05:01:16

本文可能会有所帮助:

您可以扩展它以添加“路径”列,就像您提到的那样选择原始节点。然后使用单个附加查询(如本文中所述),您可以获取路径中的其余节点。

This article might help:

You could extend it to add the "path" column like you mentioned to select original node. Then using a single additional query (as described in the article), you could grab the rest of the nodes in the path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文