0

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..

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by maks91
0

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.

Edited by jmo: n/a

0

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

0

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!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.