unistake Posted February 22, 2008 Share Posted February 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
freenity Posted February 25, 2008 Share Posted February 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Then you would need to compare that new code to your existing codes to insure it's not already being used. Quote Link to comment Share on other sites More sharing options...
freenity Posted February 25, 2008 Share Posted February 25, 2008 Then you would need to compare that new code to your existing codes to insure it's not already being used. Right That would make the unique part. Quote Link to comment Share on other sites More sharing options...
unistake Posted February 26, 2008 Author Share Posted February 26, 2008 how! great help. too some time to do it but its done! thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.