Answer the question
In order to leave comments, you need to log in
Multilevel database nesting?
Good afternoon everyone! Please tell me in which direction to dig in order to most effectively implement the scheme with a referral. 20 nesting levels.
It looks like this:
Андрей
(LVL1) Дмитрий
(LVL2) (LVL1) Максим
(LVL3) (LVL1) Валентин
(LVL4) (LVL1) Олег
Answer the question
In order to leave comments, you need to log in
Add a link to the parent user ( parent_id ).
And in order to have quick access to the entire chain and not be perverted, you can make an additional field in which to register this very chain. For the user Maxim ref_chain = Andrey/Dmitry . Add triggers to the table to check for chain updates. When accruing bonuses, you can split the ref_chain and accrue to each depending on the level (index). If there are a lot of requests, then you can make a separate table in which the links will be written explicitly for each user (to avoid dynamic building of links):
Андрей | level 0 | null
Дмитрий | level 1 | Андрей
Максим | level 1 | Дмитрий
Максим | level 2 | Андрей
You need to dig towards data storage. To store such a structure, one table and two tables and a table with views and anything else are suitable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question