Hello
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

Recommended Answers

All 5 Replies

Lookup the UUID() MySql function.

Lookup the UUID() MySql function.

Hi
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?

Hi
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;
$hash=md5($hash);
then the substr();

Be a part of the DaniWeb community

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