|
--
--table's structure ' category '
--
CREATE table IF not EXISTS ' category ' (
' id ' int (one) not NULL Auto_increme NT,
' type ' int (one) not null COMMENT ' 1 for Article Type 2 for product Type 3 for download type ',
' title ' varchar NOT NULL,
' lft ' int (one) not N ull,
' RGT ' int (one) not null,
' lorder ' int (one) not null COMMENT ' sort ',
' create_time ' int (one) not NULL,
P Rimary KEY (' id ')
) Engine=innodb DEFAULT Charset=utf8 auto_increment=10;
--
--Export the data in the table ' category '
--
INSERT into ' category ' (' id ', ' type ', ' title ', ' LfT ', ' rgt ', ' lorder ', ' CR Eate_time ') VALUES
(1, 1, ' Top columns ', 1, 1, 1261964806),
(2, 1, ' Company Profile ', X, M, 1264586212),
(3, 1, ' News ', A, 1264586226,
(4, 2, ' company Products ', ten, One, 1264586249),
(5, 1, ' Honors ', 8, 9, M, 1264586270),
( 6, 3, ' data downloads ', 6, 7, 1264586295,
(7, 1, ' recruitment ', 4, 5, 1264586314),
(8, 1, ' Message board ', 2, 3, 50, 1264586884),
(9, 1, ' president ', 1267771951, n);
The
/**
* Displays the tree, displaying all nodes.
* 1, get the left and right values of the root node first (the default root is the title of the "top-level directory").
* 2, query the left and right values in the root node of the value range of records, and sorted by the left value.
* 3, if the right value of this record is greater than the previous record of the right value is a subcategory, the output time with spaces.
* @return Array
**/
function Display_tree () {
Get the value to the left and right of root
$arr _LR = $this->category->where ("title = ' top Column '")->find ();
Print_r ($arr _LR);
if ($arr _lr) {
$right = Array ();
$arr _tree = $this->category->query ("Select ID, type, title, RGT from category WHERE LfT >=". $arr _lr[' LfT ']. " and LfT <= ". $arr _lr[' RGT ']." ORDER by LfT ");
foreach ($arr _tree as $v) {
if (count ($right)) {
while ($right [count ($right)-1] < $v [' RGT ']) {
Array_pop ($right);
}
}
$title = $v [' title '];
if (count ($right)) {
$title = ' | | '. $title;
}
$arr _list[] = array (' ID ' => $v [' id '], ' type ' => $type, ' title ' => str_repeat (', Count ($right)). $title, ' name ' = > $v [' title ']];
$right [] = $v [' RGT '];
}
return $arr _list;
}
}
|