tags:

views:

26

answers:

1

I have a MySQL table data type integer field. the value is stored as 1, 2, 3 .., 10000.

I want to format it with starting from 00001, 00002, 0003 etc., (the whole number to be 5 digit).

Is there any function to do?

or how do i set it manually in phpMyAdmin..

+5  A: 

You can change the column type to INT(5) ZEROFILL. From the documentation:

When used in conjunction with the optional extension attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004.

Example:

CREATE TABLE table1(x INT(5) ZEROFILL);
INSERT INTO table1 VALUES(4);
SELECT * FROM table1;

Result:

00004
Mark Byers
how can i add ZEROFILL in editing the table structure? i got only Field, Type, Length/Values, Default, Collation, Attributes, Null, AUTO_INCREMENT, Comments, MIME type, Browser transformation, Transformation options.. where can i set the ZEROFILL value?
vrynxzent
Set the attributes to UNSIGNED ZEROFILL.
Mark Byers
there it is.. :) thanks for the comments..
vrynxzent