php - How to make multi-level user referral system
I'm working on a multi-level referral system for signup based on PHP, but I can do the signup process to first level only. The referral system levels are managed from administrator control panel.
Table: referral_levels
id referral_level
-------- --------
1 1
2 2
3 3
4 4
Table: referrals
id new_user refferal_level referral_user_id
-------- --------
On user signup I want to check the following:
1. If the current user who signup is referred by (1)another user - DONE!
2. If the (1)another user has been referred by (2)someone else
3. If (2)someone else is referred again by "x" user and so on...
I'm confused how to write the code for p.2 and p.3 when the signup form is posted and have to check who is referred by who and insert the data for sub-level referrals.
Answer