How to make a multi level referral system in php


I want to make multi level referral system in that if A,B, C,D,E are registered user of a site then B is referred by A and C is referred by C and so on. In my site there is system for earning incentive. I want to show how much money A has earned through B and B through C and likewise.

I want simply show referrals name and their number in A’s profile and portion of money earned from each referral.

i have downloaded a script from this site. The demo is here:

And i have two types of users in my site: normal user and premium user. I want to generate ref id only for premium users. what will be the table structure?

very sad to see that no replies till now…if anybody have some idea please share with me.

This not a php problem but a relational database problem, how one user is related to other users. Assuming that each user is referred by only one user you just need a “referred_by_id” field and a good use of MySQL queries should return all the results you need.

This thread might get better answers at the database board.

thanks for your reply. I asked here because i have a script and today i made another script which comprises several nested while loop. Now question is that using several nested loop can be safe i mean no problem on server speed if more users visit that page.
Because this would be used on social networking site.