Hi people,

My issue is more of a MySQL issue than php.
I am trying to store a 3digit integer value with a leading Zeros in front such as 001

i have a company table , which auto increments the id as 001, 002, 003...and so on...
In the company table i also have a country radio box..
Which has two country names,
eg: India, Australia..

So when creating the company..
The user types in the data and select a country eg: India,
The Id should be I001,
The next record if he chooses Australia,,, then it will be
A002 ... A003, I004..and so on...till A999(as the last record).

Can anyone help me how to implement this?..

Ur help is much appreciated...
Thanks in advance..

Recommended Answers

All 4 Replies

You're going to run into many problems trying to implement this. MySQL will not auto-increment an id like this, nor will it increment with leading zeroes. You would have to determine the next number within your code. Could I ask the reasoning for this type of customer id?

If your business requirements leave you no other options, my initial thoughts are to use a separate table to keep track of what country/number code should be used for the next customer added.

Member Avatar for diafol

ditto. Use a normal increment for your users.

Hey guys,
Thanks for ur help...I managed to solve it...
I used Zerofill..
Thanks again guys..

This is For I001 assuming a varchar(4) datatype

1)Store the string in I001 $str
2)Substring the first character to $chr
3)Add 1 to int(str) and store it in $num -> 2
4)$newstr=$chr
5) if($num<10)
$newstr.="00".$num;
elseif($num<100)
$newstr.="0".$num;
elseif($num<1000)
$newstr.=$num
6)echo $newstr

Hope this solves your problem!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.