The code of the PHP tree, you can nest any layer _php foundation

Source: Internet
Author: User

PHP Tree code, you can nest any layer.?
file://establishes the main function of the tree, passing the argument as the number of the root node and the caption of the root node
function Create_tree ($rootid, $roottilte) {
Print_parent_from_rootsortid ($rootid, $roottilte);
}
file://a function to print the root node div header
function Print_parent_from_rootsortid ($rootid, $roottilte) {
$parent _fullname= "R". $rootid. "                      Parent "; File://div Parent Difference Flag
$parent _id= "R". $rootid;
$parent _pic= "R". $rootid. " IMG ";
echo "
<div class=parent id= $parent _fullname><a
Href=\ "Http://www.csdn.net/expert/menu.shtm#\"
Onclick=\ "ExpandIT (' $parent _id '); Return false\ ">Src=\ "image/folderclosed000.gif\" width=19> $roottilte </A></DIV>;

Global $cursor _tree;
$Bottom _flag=0;
$len =strlen ($rootid) +2; file://Child encoding is the parent encoding length plus 2
$query = "Select Resourcesortno,resourcesortname,sectionbottomflag
From Tbsort
Where Length (Resourcesortno) = $len and resourcesortno like ' $rootid% '; File://sql Query Statement
Ora_parse ($cursor _tree, $query) or die;
Ora_exec ($cursor _tree);

$child _fullname= "R". $rootid. "                     Child "; File://div Child Difference Flag
echo "<div class=child id= $child _fullname>"; file://Print a DIV sub-header
while (Ora_fetch ($cursor _tree)) {
$Sort _no = Trim (Ora_getcolumn ($cursor _tree,0));
$Sort _title = Trim (Ora_getcolumn ($cursor _tree,1));
$Bottom _flag = Trim (Ora_getcolumn ($cursor _tree,2));
Print_child_from_rootsortid ($Sort _title, $Sort _no, $Bottom _flag); file://Loop call Print child encoding function
}
echo "</DIV>";

}
file://to determine whether it is a last-level flag, and print a child-encoded function
function Print_child_from_rootsortid ($Section _title, $Section _no, $Bottom _flag) {
Global $num;
$len =2* $num +2;
for ($j =0; $j < $len; $j + +) {
echo "";
file://a loop of spacing between output nodes

if ($Bottom _flag==1) {
echo "

<a href=\ "http://www.csdn.net/expert/exchange.asp\" target=forum> $Section _title</a><br> ";
}else{
$p _id= "R". $Section _no;
$p _pic= "R". $Section _no. " IMG ";
echo "

<a href=\ "http://www.csdn.net/expert/exchange.asp\" onclick=\ "ExpandIT" (' $p _id '); Return false\ "> $Section _title</a><br>";
$child _fullname= "R". $Section _no. " Child ";
echo "<div class=child id= $child _fullname>"; file://Print DIV Child flag Header
Find_allchild_from_rootsortid ($Section _no); FILE://Lookup Child level content-----nested recursive function armour
echo "</DIV>"; file://Print div sub-label tail

}

}
file://queries all child-encoded functions
function Find_allchild_from_rootsortid ($Section _no) {
Global $handle, $num;
$num + +;
$cursor _ary[$num] = Ora_open ($handle);
$len =strlen ($Section _no) +2; File://μ?μ?xó?? ±e±ào?3¤?è
$query = "Select Resourcesortno,resourcesortname,sectionbottomflag
From Tbsort
Where Length (Resourcesortno) = $len and resourcesortno like ' $rootid% '; File://sql Query Statement
Ora_parse ($cursor _ary[$num], $query) or die;
Ora_exec ($cursor _ary[$num]);
while (Ora_fetch ($cursor _ary[$num]))
{
$Sort _title = Trim (Ora_getcolumn ($cursor _ary[$num],1));
$Sort _no = Trim (Ora_getcolumn ($cursor _ary[$num],0));
$Bottom _flag = Trim (Ora_getcolumn ($cursor _ary[$num],2));
Print_child_from_rootsortid ($Sort _title, $Sort _no, $Bottom _flag); file://Print all child nodes-----nested recursive function b
}
$num--;
}


?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.