Forum Moderators: coopster

Message Too Old, No Replies

Generate Random Id / Unique Id

         

adammc

12:32 am on Aug 4, 2006 (gmt 0)

10+ Year Member



Hi Folks,

I am creating an affiliate system for a website and am a bit stuck as to how to generate a unique id for each affiliate when they register.

In my mysql table I will have a unique 'id' (auto inc) and I then want to have an affiliate_id column. Can I get the DB to give auto increment the id numberr using these letters beforfe the id number 'aff-'

example:

aff-1
aff-2
aff-3

Or should I use php to generate this?

omoutop

5:55 am on Aug 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The auto-increase value is only numbers.

You may try one of the following:
a) get the auto-id from db and construct you own unique id (like your example aff-3 if your auto-id is 3)
b) get your PHPSession id and store it
c) construct your own session id-like string with something like


$session_id="";
srand((double)microtime()*1000000);
$session_id = md5(uniqid(rand()));

d) construct any random string using rand() and range() functions

coopster

3:14 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I wouldn't store the extra 4 characters 'aff-' in the database. And your AUTO_INCREMENT column already identifies them as unique in your database table so no need to keep redundant data in there. I guess what I'm trying to say is your unique AUTO_INCREMENT id is your affiliate id.