I would like to create a reference field.
I would like it ti have a fixed number of charaters/numbers, just like the videos reference of YouTube.
Is there a mysql/php function to handle that? I mean a function that generates a unique string that doesn't exist already in the table.

Help appreciated
Thank you

Lookup the UUID() MySql function.

Lookup the UUID() MySql function.

Thanks for the tip.
I have noticed that UUID function returns a always a different string,
but i would like to generate one with a fixed length - 10.
I now i could substring the returned string but that is contrary to what i want - the substring may already exists and i want to generate always a new one. Any idea?

I just used a md5 hash of a input variable and then a substr
of 10 characters. Then i make select on the table to check if is a unique id;
if yes Ok; if no just warn the user to change the input variable.

This is what I normally do:
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,10);

I did almost the same but with:
$hash = date(DATE_RFC822).$input_user_var;
then the substr();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.