pioneerx01 Posted January 4, 2011 Share Posted January 4, 2011 In MySQL my table has auto increment ID for each record, fairly straight forward. How do I set this ID number to be always 4-digit (I am never going to go over 9999 in this table)? So, record 1 is 0001, record 135 is 0135, and so one... I did not find a really definite answer in Google. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/223339-how-to-set-id-to-be-a-4-digit-id-auto-increment/ Share on other sites More sharing options...
requinix Posted January 4, 2011 Share Posted January 4, 2011 Leave the numbers in the table without the zero padding. In PHP, use something like sprintf to add them when you display them. echo sprintf("%04d", 1); // 0001 Quote Link to comment https://forums.phpfreaks.com/topic/223339-how-to-set-id-to-be-a-4-digit-id-auto-increment/#findComment-1154514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.