php唯一的字母数字id
我看过一些关于此的帖子,但没有什么完全适合我想做的事情。我几乎想在这个脚本中为客户端生成一个新的 id。我想要做的是将一个新条目添加到我的数据库中,获取 id,然后乘以 A1A1
或类似的内容。所以它就像
A1A1 - 1st id
A1A2 - 2nd id
A1A3 - 3rd id
(等等堡垒)。
有人知道我应该从哪里开始吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需增加您的字符串:
在 Ideone 上查看
Just increment your string:
See it on Ideone
不确定这是否有效,但通常会根据当前微秒生成一些连续的十六进制数字。
http://www.php.net/manual/en/function.uniqid.php
Not sure if this would work, but typically generates somewhat sequential hexdecimal numbers based on the current microsecond.
http://www.php.net/manual/en/function.uniqid.php
如果您使用 SQL 数据库,我强烈建议您检查自动增量。例如,这里是 mysql 自动增量。
If you are using a SQL database, I would highly suggest checking out auto increment. For example, here is auto-increment for mysql.
您可以将整个 id 拆分为字母和数字。然后增加相应的数字并连接回来。如果必须删除记录,请注意重新排列顺序。
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.