About PHP, MySQL, binary tree master to help, how to calculate whether a node below a node

Source: Internet
Author: User
About PHP, MySQL, binary tree master to help, how to calculate whether a node below a node?
This post was last edited by kwdpx on 2013-09-05 16:57:47




Database member Structure:
Number ancestor ID Amount
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 9
......

Like to know id:1021 's not under 1003? If it is displayed in, if it is not below 1003, the display is not in:

if () {
echo "in";
}else{
echo "not";
Exit ();
}

Share to:


------Solution--------------------
Organized into binary tree data structure, it is obvious through recursive query can be found.
------Solution--------------------
I'll pick up the points.



if ($row [0] = = $b)




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.