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
https://forums.phpfreaks.com/topic/92424-create-unique-referral-codes-for-members/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.