Tomorrow (already today, hehe) I will provide a test page for everyone to see (because I can only dial the Internet in the dorm, IP address is not fixed)
*/
/** recursive display of child node functions
*
*
* @param conditions for $SearchPattern lookup (like)
* Number of layers @param $BaseNum nodes
*/
function Listchildtree ($SearchPattern, $BaseNum) {
Global $Tree;//declares that the handle to the connected database is globally
$SQL = "Select Departmentid,departmentname from Test where DepartmentID like ' $SearchPattern '"; Find child nodes
$QueryChild = $Tree->query ($SQL);
while ($Result = $Tree->fetch_array ($QueryChild)) {//Remove child node
$Space = "";
for ($j =0; $j < ((strlen ($SearchPattern)/3)-$BaseNum); $j + +)
$Space. = ""; Set the distance before the display node, where the HTML of the space is automatically replaced by the ""
$ChildDepartment =trim ($Result [0]). " ___";
$CHILDSQL = "SELECT count (*) from the test where DepartmentID like ' $ChildDepartment '";//find child node of child node
$ChildResult = $Tree->query_first ($CHILDSQL);
$TableId = "Ta". Trim ($Result [0]); Set the table ID
$TablePic = "Ta". Trim ($Result [0]). " Pic "; Set Picture ID
if ($ChildResult [0]<1) {//If the node for the child node is not found, the-picture is displayed
?>
"Class=" > "F1"
?>
',' ') "style=" Cursor:hand ">"src=" parent.gif "border=" 0 "align=" absmiddle "width=" "height=" >"Class=" > "F1"
Listchildtree ($ChildDepartment, $BaseNum);//recursively call the function itself to display other child nodes}//end if?>
}//end function?>
<title>Infinite level Menu Test</title>
Require ("do_mysql.php"); $Tree = new Db_sql; $Tree->connect ();//Connect to the database and switch to your own code as needed
$SQL = "Select Departmentid,departmentname from test where length (DepartmentID) =3";//propose the topmost node (ancestor node), modify it as needed $Result = $Tree->query_first ($SQL); ?>
">
$FirstDepartment = $Result [0]; $BaseNum =strlen ($FirstDepartment)/3;//compute the number of layers, which is a bit redundant because it must be the first $SearchPattern = $FirstDepartment. " ___"; Set search Criteria Listchildtree ($SearchPattern, $BaseNum); Child node?> showing ancestor node
|
|
Because the test table is designed to be very simple:
CREATE TABLE Test ( ID Mediumint (8) unsigned not NULL auto_increment, #流水号 DepartmentID varchar (+) not NULL default ' ', #单位代号 Departmentname varchar (+) not NULL default ' ', #单位名称 KEY ID (ID) )
Data insertion code I'm not going to come out here and give it to everyone (it's easy to write, I'm sure everyone can write it)
The rules for the data table are:
001 is the first level (if 999 is not enough, please add it yourself) 001001 is the first child node of 001, and the second child node of 001002 is 001 001001001 is the first child node of 001001, and so on ...
I only set a "ancestor" (001), so in the program is called directly, can be set according to the needs of their own, and the code to make simple changes!
Well, it's here, if you have questions welcome and I discuss! Best wishes for a happy working day! Suck a cigarette first and sleep! Tired! (because just wrote a webftp, if any siblings need to please mail me) */
?>
http://www.bkjia.com/PHPjc/314993.html www.bkjia.com true http://www.bkjia.com/PHPjc/314993.html techarticle ?/* See a lot of friends ask the infinite level menu problem (in fact, there is a level, after all, to be subject to a convenient condition, such as: Database field type, etc.), ... |