Link to home
Start Free TrialLog in
Avatar of AymanAdam
AymanAdam

asked on

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.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

$id=42;
$id=sprintf("%08d",$id);
$id=sprintf("%s%08d",$usertext,$id);
Avatar of AymanAdam
AymanAdam

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks ahoffmann,

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