Sql 多链表
我正在尝试显示可以采取某些步骤的顺序。有些步骤可以同时执行,而另一些步骤则必须按特定顺序执行。我已经将数据存储在 SQL 表中,只是希望能够将其提取到 PHP 数组或其他内容中,以便可以将其打印出来。
数据存储在1个sql表中,有2个字段。第一个是 stat(这是该块的编号),第二个是 prereq,它标识前一个块(这可能是其他一些统计数据)。如果 prereq 字段为空,则这是起点。结束点是没有其他行时。
第一个示例:
status_number prereq
------------- -------
3 NULL
4 3
5 4
6 4
7 5
7 6
8 7
概念上看起来像这样:
我正在考虑首先以可视方式打印此内容我想将数据放入 PHP 数组中,并使用嵌套数组来垂直排列 2 个统计数据(在本例中为 5 和 6)。因此,该数组将如下所示:(3,4,(5,6),7,8)。我怎样才能将数据转化为这种形式?感谢您的帮助!
I'm trying to display the order in which certain steps can be taken. Some steps can be taken simultaneously, while others have to follow in a particular order. I have the data already in an SQL table, and just want to be able to pull this into a PHP array or something so I can print it out.
The data is stored in 1 sql table, with 2 fields. The first is stat (which is the number of this block), the second is prereq, which identifies the predecessor (which would be some other stat). If the prereq field is null, this is the starting point. The ending point is when there is no other rows.
1st example:
status_number prereq
------------- -------
3 NULL
4 3
5 4
6 4
7 5
7 6
8 7
Looks like this conceptually:
I'm thinking to visually print this, first I want to get the data into a PHP array, with nested arrays for where I would have 2 stats vertically (in this case, 5 & 6). So, the array would look like: (3,4,(5,6),7,8). How can I get the data into this form? Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这应该有效,尽管我必须承认我还没有测试过它:
I think this should work, though I have to admit I haven't tested it:
在这里,它可能需要通过
输出进行一些调整:
Here you go, it may need some tweaking though
Outputs: