Jump to content

create unique referral codes for members


unistake

Recommended Posts

I want to be able to create a unique referral code (e.g. FTCGEX3!) for each member - so that they can pass it on to their friends and get commission.

 

Does anyone know of a free script I can download from somewhere on how to create a referral code?

many thanks

 

 

also...

can someone tell me how to link up two tables in a database. say if each table had the referral code 'FTCGEX3' i want to be able to SELECT * FROM 'table' WHERE 'refcode'=FTCGEX3.

 

thanks a bunch

Link to comment
Share on other sites

to make a unique referral code is quite easy use this function as example:

 

function generate_code($length)
{
    $data[] = array(1,2,3,4,5,6,7,8,9,0,'a','b','c','d',e','f');
    $res = '';
    for ($i=0;$i<$length;$i++)
    {
        $res .= $data[rand(0,count($data))];
    }
    return $res;
}

 

This code will only return a randomly generated code as a string, but only symbols from 0 to 9 and a,b,c,d,e and f

example result:  'a63f9c'.... You can change it adding more letters or symbols like */,. etc

The length parameter is for setting how many symbols you want to include in 1 code

 

 

can someone tell me how to link up two tables in a database. say if each table had the referral code 'FTCGEX3' i want to be able to SELECT * FROM 'table' WHERE 'refcode'=FTCGEX3.

 

for example you have 2 tables:

 

tableA

tableB

each table has a field name `code`

 

You can do this:

 

SELECT tableA.id, tableA.code, tableA.username, tableA.idontknowwhatelse FROM tableA, tableB WHERE tableA.code = tableB.code;

 

So basically all you do is put : table . field and that how you can refer to other tables in the same query.

Link to comment
Share on other sites

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.