How to Auto Generate 9 Digit Alpha Numeric Code

10 years 4 months ago #236919 by nant
Just another thought for you to consider.

You might want to prepopulate a new table in your database that has the unique digits pre-generated in the format you wish. The table can also have an extra column to allow you to mark if a code has been used or not (this way you will not use the same code once its assigned).

You can then have an autoaction that picks up the first available free code and copies it over to a read-only cb field for a user and marks it as used also in the initial table.

Something to consider.
The following user(s) said Thank You: naturallink

Please Log in to join the conversation.

10 years 4 months ago #237447 by naturallink
Replied by naturallink on topic How to Auto Generate 9 Digit Alpha Numeric Code
9 digits when using alpha-numeric actually = 34,162,713,446,400 permutations, that's plenty :)

Extra question though, sorry if this is too much, but have to ask...

Lets say Member joins to make a profile
When the Auto gen UUID is created as per previous query
Instead of one box of 9 digits
Could you have it split into 3 boxes of 3
ie (4GD) (7YF) (CD9)
So it will be easier on the eye than just 4GD7YFCD9

Thanks in advance

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #237467 by krileon

Lets say Member joins to make a profile
When the Auto gen UUID is created as per previous query
Instead of one box of 9 digits
Could you have it split into 3 boxes of 3
ie (4GD) (7YF) (CD9)
So it will be easier on the eye than just 4GD7YFCD9

Yes, it's a database query so you can format it anyway you want using SQL formatting functions. I would keep the formatting simple though such as in the below example.

4GD-7YF-CD9
CONCAT_WS( '-', SUBSTRING( UUID(), 1, 3 ), SUBSTRING( UUID(), 4, 6 ), SUBSTRING( UUID(), 7, 9 ) )


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: naturallink

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #237575 by naturallink
Replied by naturallink on topic How to Auto Generate 9 Digit Alpha Numeric Code
For nant - thankyou for your feedback.

Once this project comes out of beta, we can expect tens of thousands of registrations - a prepopulated table would be impractical. With a smaller registration database i can see that working, but in this case we really need it automated.

Please Log in to join the conversation.

10 years 4 months ago - 10 years 4 months ago #237576 by naturallink
Replied by naturallink on topic How to Auto Generate 9 Digit Alpha Numeric Code
@ krileon - thank you for responding to my colleague but to add additional information.

Ive been researching stackflow and a few other php forums regarding the auto gen of the unique number and there are several options available some of them quite straight forward others not. The UUID solution you mentioned first of all seems to generate the correct random unique serial we need however the client requires the UUID to be in a set format of 9 digits and not 13.

I have also found this solution on stack flow (look to member scots solution). His solution is using opensll instead however im having trouble getting the code to work. Apparently openssl is the recommended solution for generating random alpha numeric for php. Getting the bugger to display however is another thing all together.

stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string


Once the UUID is generate i then need to auto fill it into the UUID field on comprofiler for that client (at the point of registration) but before that it needs to be cross checked against the PHP database to ensure the UUID (however remote) has not been assigned before.

Once thats done - then we can consider the style format.

Prioity is generate UUID - either from uiqid or opensll or script - then select set characters as per the end line clients requirements - check that against the php database - then display in user friendly format on the clients comprofiler profile and finally enable it to be downloaded for send to hard printing.

Please Log in to join the conversation.

10 years 4 months ago #237629 by krileon

however the client requires the UUID to be in a set format of 9 digits and not 13.

As explained and exampled you can format it quite literally anyway you want. My above example is simply an example and you're welcome to adjust it as needed.

I have also found this solution on stack flow (look to member scots solution). His solution is using opensll instead however im having trouble getting the code to work. Apparently openssl is the recommended solution for generating random alpha numeric for php. Getting the bugger to display however is another thing all together.

There's no reason for such a solution. Unique IDs can be generated with SQL perfectly fine or simple PHP if wanting to use PHP.

Once the UUID is generate i then need to auto fill it into the UUID field on comprofiler for that client (at the point of registration) but before that it needs to be cross checked against the PHP database to ensure the UUID (however remote) has not been assigned before.

The chances of two IDs being the same generated from UUID is basically none. You shouldn't have to check it against your database.

Prioity is generate UUID - either from uiqid or opensll or script - then select set characters as per the end line clients requirements - check that against the php database - then display in user friendly format on the clients comprofiler profile and finally enable it to be downloaded for send to hard printing.

You can generate the unique ID as shown in my previous replies. You can then use CB Query Field to format it on display to be user friendly. In database it could be stored as D34fSD346GLP9 for example, which is fine and best approach, you then can format that using SQL format functions for display on profile using CB Query Field.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.230 seconds

Facebook Twitter LinkedIn