Jump to content

Recommended Posts

hi guys.

i want to implement a referral system. a member can only refer using a form in the memebers area. on the referral form, i have a hidden field which is his referral id and a unique code (md5 generated link) and a field for the email address he wants to refer. once he sends the mail, a referal link (md5 generated, for uniqueness and to curb cheating) is sent to the email so that once he clicks, it takes him/her to the registration area.


on my database table

referrer_uid - the unique id of person referring someone
referred_uid - the unique id of person being referred
ref_code - the md5 generated code which is used on the link sent
referred_email - the email address of the person being referred
status - once a member sends a refer link, status is set to Referal sent
date_referred - the date the refering took place
date_accepted - the day the referred was accepted (i dont want this to change on clicking a referal link or registration cos not everyone gets accepted to avoid spurious referals)


my question is how do i create a traversal tree with this. i read about traversal tree on sitepoint but when i tried to implement the examples, it didnt work for me and i noticed it was an old post.

note: i intend giving points based on the child/tree and it could be as deep as possible. also if my method is wrong, ideas are higly appreciated.

thanks
 

Link to comment
https://forums.phpfreaks.com/topic/293053-traversal-tree-referal-system/
Share on other sites

Assuming I understand the question...you have members who refer other people who themselves become members..

 

You have a "Members" table which holds the member ID's and date & time of when they became members.

 

Members
------------------
Member_Id
name
email
etc 
etc
Date_Time
 
You have the "Referrals" table which holds the Member Id of the now member and the Referrer Id of who referred them and the date & time of when they were referred or actually signed up.
 
Referrals
-------------------
Member_id
email
etc
etc
Referer_Id
Date_Time
 
You can traverse by following a member -> any members that have a row/s in the referral table ->
RECURSION 
 
I'll step aside and see what the senior members have to say. It appears like a recursion problem to me at first glance.
 

Switching your database to a nested set model may be beneficial. It makes it easier to query for things like the path to the root (ie, referral path) or tree depth (how many levels of referrals a person has).

 

It's a little more complex to manage and maintain, but tends to make working with the data more efficient and sometimes easier.

 

It may help to explain more specifically what kind of things you'd like to do. Like for example you say you want to award points. How exactly do you want to award points?

Edited by kicken

Switching your database to a nested set model may be beneficial. It makes it easier to query for things like the path to the root (ie, referral path) or tree depth (how many levels of referrals a person has).

 

It's a little more complex to manage and maintain, but tends to make working with the data more efficient and sometimes easier.

 

It may help to explain more specifically what kind of things you'd like to do. Like for example you say you want to award points. How exactly do you want to award points?

How exactly do you want to award points?

for instance I give 4 points on first tree and 3points on second tree, 2points on third tree and above.

Switching your database to a nested set model may be beneficial. It makes it easier to query for things like the path to the root (ie, referral path) or tree depth (how many levels of referrals a person has).

 

It's a little more complex to manage and maintain, but tends to make working with the data more efficient and sometimes easier.

 

It may help to explain more specifically what kind of things you'd like to do. Like for example you say you want to award points. How exactly do you want to award points?

Hi kicken. I've read the link you sent, i think changing to a nested set model will do the job, but how can i switch my database to a nested set model with my given fields or any other better way. Thanks

Switching your database to a nested set model may be beneficial. It makes it easier to query for things like the path to the root (ie, referral path) or tree depth (how many levels of referrals a person has).

 

It's a little more complex to manage and maintain, but tends to make working with the data more efficient and sometimes easier.

 

It may help to explain more specifically what kind of things you'd like to do. Like for example you say you want to award points. How exactly do you want to award points?

 

Hello.

 

The problem I'm having with the link you sent me is, how do they determine the left and right values? since i cannot just insert any value to them.

 

thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.