Re: [請益] 該怎麼設計目錄的資料表呢!?
經過了以上各位大大的解析,
和網路上google的結果,變成以下的東西
function display_tree($root) {
// retrieve the left and right value of the $root node
//找到index的左右數字
$result_f = $mysqli->query('SELECT left, right FROM menu WHERE node="'.$root.'";');
$row = $result_f->fetch_array();
// start with an empty $right stack
$right = array();
// now, retrieve all descendants of the $root node
//找出所有的index底下結點
$result = $mysqli->query('SELECT node, left, right FROM menu '.
'WHERE left BETWEEN '.$row['left'].' AND '.
$row['right'].' ORDER BY left ASC;');
// display each row
while ($row = $result->fetch_array()) {
// only check stack if there is one
/*
if (count($right)>0) {
// check if we should remove a node from the stack
while ($right[count($right)-1]<$row['right']) {
array_pop($right);
}
}
// display indented node title
echo str_repeat(' ',count($right)).$row['node']."<br />";
// add this node to the stack
$right[] = $row['right'];
}
}
這樣子跑出來的樹狀圖是
index
pageB
pageC
pageD
pageE
pageF
pageG
pageBBB
pageCCC
pageDDD
雖然已經完成了...但是我發現和目標完全不符...離完成似乎還很遠阿
因為要產生的hmtl應該是
<ol class="tree">
<li><label for="subsubfolder2">index</label> <input type="checkbox" id="subsubfolder2" />
<ol>
<li>
<label for="subsubfolder2">pageB</label> <input type="checkbox" />
<ol>
<li><label for="subsubfolder2">pageC</label> <input type="checkbox" /> </li>
<li><label for="subsubfolder2">pageE</label> <input type="checkbox" /> </li>
</ol>
</li>
<li><label for="subsubfolder2">pageBBB</label> <input type="checkbox" />
<ol>
<li><label for="subsubfolder2">pageCCC</label> <input type="checkbox" /> </li>
</ol>
</li>
</ol>
</li>
</ol>
類似的東西,代表須要在php中想辦法包html進去...
所以現在重點應該是怎麼把html塞進去,繼續研究中...Orz
另外附上參考連結
http://www.sitepoint.com/hierarchical-data-database-2/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.124.195.130
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 5 之 6 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章