[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 846
  • Last Modified:

how to generate customized ID automatically using php/mysql?

hi experts!,

simply my problem is that i want to generate some id (ProjectID) automatically (user haven't to worry about entering this field), but my issue is that this id must be intelligent in other words it is not just auto incremented field. it consists of two parts (text and serial number of specific number of digits). to make it much clear lets consider this scenario:
i have a text field in my form that is filled by user, this is the field which i use to generate the ProjectID
if for example the user entered in this field the value ("test") and this was the first entery in my list of prjects then the ProjectID must be ("test00000001").
furthermore the number of digits (of the numeric part) is exactly 8 digits. i know that for the first part of the generated id it is straightforward just get user value and put it in. the problem is in the rest .
examples of generated ids:

ProjectID:
*************
iddr00000002                     -> corresponds to project number 2   -> user entered  (iddr)
amcu00000100                   -> corresponds to project number 100        -> user entered (amcu)
someText00020003            -> corresponds to project number 20003             -> user entered (someText)

i think it is clear now. one thing is that the number part must be 8 digits length, left padded with zeros as above examples exaclty.

i am using php5 with mysql 5 also and apache 1.3 (just FYI).
thanks to all participants in advance.
for more info please ask.
0
AymanAdam
Asked:
AymanAdam
  • 3
  • 2
1 Solution
 
ahoffmannCommented:
$id=42;
$id=sprintf("%08d",$id);
0
 
ahoffmannCommented:
$id=sprintf("%s%08d",$usertext,$id);
0
 
AymanAdamAuthor Commented:
ahoffmann, now how to make the numeric value auto incremented?
i mean i have to make this 8 digits auto incremented what can i do in this case?
0
 
ahoffmannCommented:
$id=42;
$id=sprintf("%08d",$id);
$id++;
$id=sprintf("%s%08d",$usertext,$id);
0
 
AymanAdamAuthor Commented:
thanks ahoffmann,

there are some minors remaining but i can deal with them.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now