作者kingoface (桑原)
看板PHP
标题Re: [请益] 该怎麽设计目录的资料表呢!?
时间Tue Jun 18 14:46:10 2013
经过了以上各位大大的解析,
和网路上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