Php traverses the tree. The child node can have multiple parent nodes. please kindly advise this post to be edited by asmd1234567 at 2013-09-12:56:42. I hope to display the parent-child relationship, A parent node can have multiple sub-nodes, and a sub-node can have multiple parent nodes. since the operation fails, I do not know whether the function I wrote is correct, sorry, & nbsp; $ result & nbsp; & nbsp php traverses the tree. the subnode can have multiple parent nodes. please kindly advise
This post was last edited by asmd1234567 at 11:56:42
I want to display the parent-child relationship. a parent node can have multiple sub-nodes, and a sub-node can have multiple parent nodes. since the operation fails, I don't know if the function I wrote is correct. sorry.
$ Result = array ();/* Parse error: syntax error, unexpected '=', expecting ',' or ';'*/
/* I originally hoped this would be a global array, but I checked it online and found it was no longer possible. I wonder if you have any good methods. thank you */
$ Result [0] = mysql_query ("select cID, number, isbasicpart from relationship where pID = '{$ id}'");/* cID is the subnode number, isbasicpart indicates whether it is a leaf node, and number indicates the number of parent and child nodes */
Echo"
";Echo"
{$ Id }"; $ I = 0;
Function buildtree ($ I ){
While ($ row = mysql_fetch_array ($ result [$ I]) { If ($ row ['isbasicpart'] = 1) Echo" |
'--' |
{$ Row ['CID']} |
'(' |
{$ Row ['Number']} |
')' |
";Else {echo"
'--' |
{$ Row ['CID']} |
'(' |
{$ Row ['Number']} |
')'"; $ I = $ I + 1; $ SQL = "select cID, number, isbasicpart from relationship where pID = '{$ row ['CID']}'"; $ Result [$ I] = mysql_query ($ SQL );
Buildtree ($ I );
}
} Echo' |
';
}
Buildtree (0 );
}
Php traverses multiple parent nodes
Share:
------ Solution --------------------
Add global $ result at 13 rows;
Multiple td tags in the function are not closed
The function generates multiple table closed tags, but only one table is marked.
------ Solution --------------------
Look at the source code (the key is to look at the design ideas. as for algorithms, there are usually not many requirements on the basic web, but it is good to go deep and write cool code, the most important thing is the design framework and mode. write more (refer to the design ideas and code specifications of the good source code)
Then there is nothing to read and there are many aspects. in this way, there is no short board of knowledge, so you can gradually have your own knowledge system.