For php and mysql, how can I calculate whether a node is under a node? At the end of this post, kwdpx edits the database's member structure from 2013-09-0516: 57: 47: No. & nbsp; superior ID & nbsp; amount id & nbsp; & about php, mysql, binary tree experts to help, how does one calculate whether a node is under a node?
This post was last edited by kwdpx at 16:57:47
Database member structure:
Amount of the superior ID
Id sh1 jine
1001 999 49
1002 1001 20
1003 1001 29
1004 1002 10
1005 1003 12
1006 1002 10
1007 1006 4
1008 1003 17
1013 1008 8
1015 1006 6
1021 1008
......
For example, do you want to know that ID: 1021 is not under 1003? If it is displayed, if it is not in 1003, it is not:
If (){
Echo "in ";
} Else {
Echo "not ";
Exit ();
}
Share:
------ Solution --------------------
The data structure organized into a binary tree can be found through recursive queries.
------ Solution --------------------
I picked it up.
Function show ($ a, $ B ){
$ Res = mysql_query ("select sh1 from member where id = $ ");
$ Row = mysql_fetch_row ($ res );
If ($ row [0] = $ B)
Return 'in ';
Elseif ($ row [0] = NULL)
Return 'no ';
Else {
Echo show ($ row [0], $ B );
}
}
Echo show (1004,1001 );
Echo'
';
Echo show (1004,10031 );