简体   繁体   English

如何使用php生成唯一的自动增量格式化格式的数字

[英]How can generate unique auto incremement formatted number using php

I have a loan application form and it has application No field. 我有一份贷款申请表,里面有“申请号”字段。 it should be readonly. 它应该是只读的。 Now i want to generate auto increment formatted number and show inside my text box. 现在,我想生成自动增量格式的数字并显示在我的文本框中。 application No should be like "LN/SS-DATE-000". 申请号应类似于“ LN / SS-DATE-000”。 can anyone explain, How to generate this number using php and echo in my text box. 谁能解释,如何在我的文本框中使用php和echo生成此数字。

If you want to use a unique auto increment number, then you need to store the last generated number somewhere. 如果要使用唯一的自动递增编号,则需要将最后生成的编号存储在某个位置。 If you use a database, then the easiest is to store it in a table: 如果使用数据库,那么最简单的方法是将其存储在表中:

CREATE TABLE `counter` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `stub` char(1) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `stub` (`stub`)
) ENGINE=MyISAM

Use the following queries to increase the counter and get the actual value: 使用以下查询来增加计数器并获得实际值:

REPLACE INTO `counter` (`stub`) VALUES ('a');
SELECT LAST_INSERT_ID();

You can read more about this technique on Flickr's blog . 您可以在Flickr的博客上了解有关此技术的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM