Php traverses the tree. The child node can have multiple parent nodes. please kindly advise that this post was last edited by asmd1234567 at 11:56:42
Php traverses multiple parent nodes
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 expected this to be a global array, but I checked it online and found that it is no longer possible. do you have any good ideas, thank you here */$ result [0] = mysql_query ("select cID, number, isbasicpart from relationship where pID = '{$ id }'"); /* cID indicates 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 );}
Reply to discussion (solution)
A parent node can have multiple child nodes, and a child node can have multiple parent nodes.
It's not a tree, it's a network.
You have many to many ....
Does this code look dizzy?
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.
A parent node can have multiple child nodes, and a child node can have multiple parent nodes.
It's not a tree, it's a network.
Thanks for reminding me :)
You have many to many ....
Thanks for reminding me :)
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.
Thank you very much. although there are still problems, it is a step closer to the target. I just started to learn the php language. the upstairs said that the code I wrote was not very good. I would like to ask whether the problem is wrong or the code writing is not standard. I think sometimes I don't think of any good algorithms, because there are few programming skills. Do you want to read more books? do you want to memorize the classical algorithms? Thank you again for your answer. thank you!
You are a recursive query, and there is no problem.
Check whether the query key is correct.
If you use a table to output the result, if the tag is not matched, the correct query results will also produce chaotic results.
We recommend that you do not use a table first and correct the data first.
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.
You are a recursive query, and there is no problem.
Check whether the query key is correct.
If you use a table to output the result, if the tag is not matched, the correct query results will also produce chaotic results.
We recommend that you do not use a table first and correct the data first.
Thank you very much!
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.
Thank you very much. I will work hard and wish you a better one :)
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.
I would like to ask another question: where can I find excellent source code? Are there any good books or websites, or some cool man's code is good?
A parent node can have multiple child nodes, and a child node can have multiple parent nodes.
This is not a tree. it's called a net. The answer is classic. how can I find a tree like lz! Your data structure is not clear. how can it be output cyclically!