For php and mysql, how can I calculate whether a node is under a node?-php Tutorial

Source: Internet
Author: User
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 );

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.