Answer the question
In order to leave comments, you need to log in
How to make a referral counter in PHP?
Guys, there is a multi-level referral system on the site. How to implement a referral counter and sub referrals?
Let's say Vasya registered on Petya's referral, and Kostya registered on Vasina's. It is necessary that the record that the number of Petya's referrals is 2 (two) gets into the database.
It is the logic of the code that is needed, I will write the code myself. Thanks in advance!
Answer the question
In order to leave comments, you need to log in
For starters: each user, in theory, should have an inviter field, or any other field, where the ID of the user who invited him is stored. Let's say:
| id | username | inviter |
|----|----------|---------|
| 1 | abc | null |
| 2 | abcd | 1 |
| 3 | abcde | 2 |
| 4 | abcdef | 1 |
SELECT COUNT(*) FROM table_name WHERE inviter = {НОМЕР_ПОЛЬЗОВАТЕЛЯ}
Recursive crawl through the "tree" of referrals with an accumulative calculation.
Or.
When a new sect of a referral appears, add units to each higher in the hierarchy.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question