I want to get all down-lines of a father in a binary tree, each father has left and right arms, each arm has left and right arms etc.. like the following image. In my database i have a table called users, each user has a father id and position which is L or R.
Here is my function .. but it still don't get all downlines. like the following image.
Two things stand out to me:
$iargument and the use of$this->downline_id_arr.Consider doing:
Now you don't need the
$ivariable or$this->downline_id_arr.Consider querying by level instead:
Typically less queries is faster so you should see better performance.