Forum Moderators: coopster

Message Too Old, No Replies

auto generate a unique id

trying to generate a confirmation code.

         

maxxtraxx

9:50 pm on May 8, 2003 (gmt 0)

10+ Year Member



hi,

i would like to auto generate a unique number when a record is inserted. is there a way to do this other than setting the field datatype to 'auto-increment'.

basically, i want to generate a confirmation code for a scheduling system i have built and auto-incrementing is too generic for the confirm code.

thanks for any info you can provide!

Robber

10:51 pm on May 8, 2003 (gmt 0)

10+ Year Member



I suppose you would want to be looking at things like:
* time
* process if
* ip

and generating an id from these. Should be pretty unique.

DrDoc

11:05 pm on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can always use an MD5 string based on the current time...

Robber

11:22 pm on May 8, 2003 (gmt 0)

10+ Year Member



Doc,

What level of accuracy would current time function return - in practical terms enough for a unique id? Be intersting to know as I've not done much in this area.

Cheers

grahamstewart

11:48 pm on May 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The microtime() fucntion in PHP gives you the current time in seconds and microseconds [dictionary.reference.com].

Thats pretty accurate!

jatar_k

12:35 am on May 9, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not sure if you are using php but if you are take a look at uniqid [php.net]

maxxtraxx

5:50 am on May 9, 2003 (gmt 0)

10+ Year Member



yes, i'm using PHP, and would like to be able to prefix the code as well. for example:

88xxx or 77xxx

thanks for all the input!

maxxtraxx

5:53 am on May 9, 2003 (gmt 0)

10+ Year Member



nice, just chked out uniqid, and it looks like that will work just peachy!

thanks again!