how to generate customized ID automatically using php/mysql?
Posted on 2007-08-07
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:
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.