SatuPortal
11-23-2002, 02:10 AM
Can anyone help me for my problem. I am new in MySQL.
I want to create a field on clients table with this :
id int(8) zerofill not null,
but when i use this field on my php script and fill in the 00101010 value, it shows 00000000 not 00101010
So what the type of the field i must use if i want to fill in the field numbers that have 00 value at front (e.g. 0010101010)
I also tried : id varchar(8) not null,
but the result was 101010 not 00101010
Thanks
wakkow
11-23-2002, 03:34 AM
Why not type CHAR instead of VARCHAR.. I think VARCHAR might be ignoring the leading 0's.
SatuPortal
11-23-2002, 11:15 AM
wakkow, i already tried to change the type to char but it only save for 1 character only. If I change to 10 character :
id char(10) not null,
the result become : id varchar(10) not null, on mySQL :confused:
I need to get the 'id' works for number like 00101010 because i use 00 at front as year 2000 identity.
matt2kjones
11-23-2002, 11:25 AM
the reason it does that, is because really, if you are looking at the number in a matamatical way
002000 is the same as 2000
thats why the 00 are removed
if you type 2000 the numbers are left there, because the zeros come after a number > 0
a way to get around this would be to use a text field
wakkow
11-23-2002, 02:34 PM
that's odd.. I created a test table and made a char id of size 10.. and it worked.. oh well. let us know if you find a fix
jtrovato
11-23-2002, 02:50 PM
ALTER TABLE `accounts` ADD `number` INT(8) UNSIGNED ZEROFILL NOT NULL
or for a new table
CREATE TABLE `test` (`number` INT (10) UNSIGNED ZEROFILL DEFAULT '0' NOT NULL)
this will work for what you are looking to do
John
SatuPortal
11-23-2002, 08:11 PM
Its work! After i drop the table and create a new table and it's work.
Thanks wakkow,
Now, i have another question, how to avoid the same number will be using for other id's ?
What command i must add to my php script ?
DoobyWho
11-23-2002, 09:49 PM
It's a MySQL property, not a PHP property. Need to set it to `unique`