Page 1 of 1

How to keep leading Zero when inserting Int into field

Posted: Mon Oct 20, 2003 9:50 am
by JayBird
I have a field in a MySQL table that i have sent to Int(4)

The numbers are going to be starting at 0001 and going upwards.

But when i insert into the field, the leading Zero's get chopped off. How can i keep them?

Do i need to change the filed type?

Thanks

Mark

Posted: Mon Oct 20, 2003 10:29 am
by Kriek
You could always add them back, no?

Code: Select all

$var = sprintf("%04s", $var);

Posted: Mon Oct 20, 2003 12:50 pm
by maniac9
In the database, specify the int column as ZEROFILL - ie.

columnName INTEGER(4) ZEROFILL

and it will keep the zeros for you