Jump to content

Unique Reference


andy295

Recommended Posts

Hi,

 

I just need someone to check that a couple of lines I've written do what I believe them to do... i.e. check my logic!

 

I'm developing a booking form for booking on events. Each booking needs a unique reference, which needs to be meaningless to the customer, so I am BASE36 encloding it.

 

As the booking is be saved to a MySql database, my approach is to use the auto-incremented ID for the record to make the reference unique. The increment starts at 10000, and I add a random number before coding to make the encoded reference longer. I then BASE36 encode it to make it appear random.

 

Am I right in thinking the reference produced WILL be unique ... provided the auto-inc ID is unique?

 

$ref = rand(100,999) . $auto_incremented_id; //e.g. 354 & 10012 = 35410001
$ref_encoded = strtoupper(base_convert($rand, 10, 36)); // e.g.UD4J8P

Thanks

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.