我想創建一個嵌套的無序列表使用PHP和MySQL(通過CodeIgniter,但我認爲這不相關)。PHP和MySQL中的嵌套列表
我見過一些解決方案似乎適用於有兩級嵌套的列表,但我需要的解決方案必須有三個級別。這是諸如此類的事情,我需要:
<ul>
<li>Top Level, Item 1
<ul>
<li>Second Level, Item 1
<ul>
<li>Third Level, Item 1</li>
<li>Third Level, Item 2</li>
<li>Third Level, Item 3</li>
</ul>
<li>Second Level, Item 2
<ul>
<li>Third Level, Item 4</li>
<li>Third Level, Item 5</li>
<li>Third Level, Item 6</li>
</ul>
</li>
</ul>
</li>
</ul>
從我的數據庫的輸出,主要有:
TOP LEVEL | SECOND LEVEL | THIRD LEVEL
Item 1 | Item 1 | Item 1
Item 1 | Item 1 | Item 2
Item 1 | Item 1 | Item 3
Item 1 | Item 2 | Item 4
Item 1 | Item 2 | Item 5
Item 1 | Item 2 | Item 6
我試圖通過從數據庫中輸出去,使用的變量要註冊的水平我在等等,但是在關閉每個列表時我陷入了一個糟糕的境地。
任何人都可以提出一個這樣做的方法嗎?
你的數據庫結構和查詢是什麼樣的? – Maximus2012
一切事物總是三分之一還是變化? – DevlshOne
@ Maximus2012 - 我的數據庫輸出是固定的,所以在描述時可能沒什麼意義。它輸出類似於我在問題中提出的內容(顯然有更多細節!)。 – davidofyork