Php traversal tree. child nodes can have multiple parent nodes.

Source: Internet
Author: User
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" ";Else {echo"
{$ Id }";
$ I = 0;



Function buildtree ($ I ){

While ($ row = mysql_fetch_array ($ result [$ I]) {
If ($ row ['isbasicpart'] = 1)
Echo"
'--' {$ Row ['CID']} '(' {$ Row ['Number']} ')'
'--' {$ 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.

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.