I will try my best to be both succinct and fully explanatory in this predicament.
On a site I manage, we allow a manager to view their "Recruiting Downline" which entails a list of all agents they personally recruited, as well as the recruits that particular agent (and so on and so on) brought to the Team.
For example:
- I recruit two Agents, A and B.
- A recruits two agents, C and D.
- B recruits two agents, E and F.
- D recruits two agents G and H.
- C, E, and F do nothing.
In the database, every individual agent record has a field for 'referring agent', which lists their recruited agent.
- As the top level, when I click "My Recruits", I am shown a list of all sub agents (because they ALL fall under my umbrella).
- A is able to view C, D, G, and H.
- B is only able to view E and F as they are his only downline recruits and they have brought nobody on board.
While this functionality works great it is flawed for two reasons:
Because of the way our PHP scripts are built, we are unable to sort the commission level data as a whole. Example: Even as the top man and I can see everybody, sorting by 'commission level' sorts my immediate agents by the criteria, then their downline as an item, then continues the sort based on my criteria. This is difficult to understand so to demonstrate, assume the table below displays the 'commission level' for ALL agents:
- A, 7
- B, 6
- C, 5
- D, 6
- E, 5
- F, 2
- G, 5
- H, 1
Note: an agent can NEVER recruit another agent at a higher level than they sit but they can recruit at ANY level below them (e.g. a 7 can recruit at 1,2,3,4,5,6 while a 3 can only recruit a 1,2).
FROM MY (high level) perspective,
While it would make sense for the data to be 'sorted by commission level' as: A, D, B, G, C, E, F, H - this is not the case.
Instead (view from top agent's perspective mind you) is: A, D, G, H, C, B, E, F
basically, every while loop depends on the DIRECT upline agent number to determine who falls next in line.
I understand this is 'very' difficult to understand but let me know if I can provide any additional understanding into our current 'sort' issue.