Php realizes three-tier distribution help

Project to achieve three-tier distribution;
rebate to all superiors (up to three levels) after database design and user registration

but I don"t have a clue. Please give me a thought.

if it is directly registered to reward 20 yuan
if it is through the QR code or link to enter the registration page, find the superior and give the superior a reward of 10 yuan
if the superior still has a superior, reward 5 yuan
if the superior has a superior, reward 3 yuan

there is really no idea for such an implementation and the establishment of a data table.
at present, the stupid way is to write a method to find a superior to give a reward of 10 yuan
when a user signs up.

then write a method to look for it again according to the superior and then look for it

.

I think this method is stupid. Is there any other better way?

how can I query the parent member of the current member three levels up by recursion?

Oct.12,2021

since it is a definite three-tier distribution, the design is designed with a three-level table, and then a statement can be checked out. Mysql is associated with three user tables,
-> table ('1')
-> join (the conditions are limited by themselves)
-> join ('3levels,
-> where (3.fid=2.id)
-> where (2.fid=1.id)
-> select


that's right, that's it, you can also add an auxiliary field.

for example, level 2 is recommended by first-level members.
level 2 is recommended by second-level members. Level 3 is recommended by second-level members so that a fixed query can be saved.


can you record
each will have a unique id level 1, there will be a numeric string if the current member id is 50, the superior is 1, there is no
00-00-01-50 when this member recommends a new member id 51, the new member will have 00-01-50-51
I don't know if this idea works


create table user {
id int unsigned not null auto_increment primary key,
name varchar (64) not null,
pass varchar (64) not null,
fid int unsigned not null,
money decimal (6 du 2) not null
} engine=innodb charset=utf8;

)

make a simple description
1, the user registers in, obtains the information, according to the landlord's meaning, should be able to get the user information as well as the recommendation information (the self-registration recommendation information is empty).
2, enter the database after getting the information, and register, fid ((which means father_id) is 0. If there is a reference, fid is set to the reference id. At this time, the referrer is the first-tier superior.
3, known references id, can know references fid, can check references' superiors. Step by step.
4, write a recursive function with id,fid and find that when fid is 0, stop. Fid is 0, that is, the top superior.
5, according to the information returned by the recursive function, confirm the total series (it is easy to confirm, return several sets of user information to know the total number of levels)
6, write a method to allocate bonuses according to the series, and call the method, which is responsible for the payment of bonuses.
finally: simple sql and simple ideas are like this. If I'm not sure how to query my superiors recursively, I will write it out to the landlord in the comments.


at most three levels, then record the three levels directly. There is no need for fId1,fId2,fId3, to do too much, initialize it when you register, check these three fields directly, and check the
down at one time. You can refer to the design of the provincial, city, county and district code


if there are only three levels, the easiest way is to directly store in a table and record the three levels of fid1,fid2,fid3, above. In this way, every time you register, you can find out all the upper three levels directly through the last introducer, so why bother to do recursion.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b7ab-dfe8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b7ab-dfe8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?