The integer 7
is the same thing as the integer 000000000000000000000000007
. They're both... ya know... seven. When stored in the database, it's actually stored as something like 000000000000000000000000007
but most MySQL clients won't bother to show all those zeros.
If it's important in your application to show these numbers using a certain number of digits, you can add back as many leading zeros as you want using the str_pad()
function:
str_pad($your_string, 10, '0', STR_PAD_LEFT);
Here, 10
is the length you want the string to be, '0'
is the character that will get added on in order to make it that length, and STR_PAD_LEFT
says to add characters to the left-hand side of the string.
If, on the other hand, the number '007'
is fundamentally different than the number '7'
, then you will have to use a VARCHAR()
field to store it. Those are no longer integers; they're strings with very different meanings.