Multi Level Referral Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bsam
Forum Newbie
Posts: 3
Joined: Wed Jan 27, 2010 5:54 pm

Multi Level Referral Script

Post by bsam »

Hi all. I need to write a sort of multi-level referral script
in a membership site,where if a member refers a certain
number of members he goes up one level,and if those
invited members invite the same number of members each, the original
members goes up another level and so on. How do I approach this kind of
situation with PHP...Thanks
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Multi Level Referral Script

Post by JakeJ »

You must start with a solid database design.

users:
id
username
level
etc

referredby:
id
referer
referee
timestamp

levels
id
description

In php, you have to generate some unique url for the user so that whoever they refer gets credit for it. There's stuff out there to generate those if you look for it. phpList will have some code for that if you tear it apart.

So when someone clicks the URL (or rather completes the registration process I assume) a query is executed which finds the level of the referer and adds one to it. Presumably this script will do other things like complete the registration too.

Now, go forth and code! If you have specific problems, let us know!
bsam
Forum Newbie
Posts: 3
Joined: Wed Jan 27, 2010 5:54 pm

Re: Multi Level Referral Script

Post by bsam »

Thanks.
Yes, the real issue is with the database logic,
can you elaborate more on how those tables are
related...
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Multi Level Referral Script

Post by JakeJ »

bsam wrote:Thanks.
Yes, the real issue is with the database logic,
can you elaborate more on how those tables are
related...
users:
id
username
level (levels.id)
etc

referredby:
id
referer (users.id for the referrer)
referee (users.id for the referrer)
timestamp

levels:
id
description

I'm not sure I can be any more elaborate than that. I'm sure your actual table structure is going to be far more involved than what I've presented, that is just a basic structure. I suggest you go do some reading on database design or you're going to get hopelessly lost trying to do this project because you won't have a meaningful data set.
Post Reply