I have seen a few post on this, but nothing that would work entirely for what I'm trying to do. Pretty much I want to generate a new id for clients in this 开发者_运维技巧script. What I want to do is add a new entry to my database, get the id, and then multiply by say A1A1
, or something like that. So it would be like
A1A1 - 1st id
A1A2 - 2nd id
A1A3 - 3rd id
(so on and so fort).
Anyone got any ideas where I should start with that?
Just increment your string:
$id = 'A1A1';
$new_id = ++ $id; // $new_id is now A1A2
See it on Ideone
Not sure if this would work, but typically generates somewhat sequential hexdecimal numbers based on the current microsecond.
uniqid();
http://www.php.net/manual/en/function.uniqid.php
If you are using a SQL database, I would highly suggest checking out auto increment. For example, here is auto-increment for mysql.
You may split the whole id into alphabets and numerals. Then increment the corresponding numeral and concatenate back. If you have to make record deletion, take care of the re-arranging the sequence.
精彩评论