ryanwood4 Posted August 28, 2009 Share Posted August 28, 2009 This may be a fairly simple question, but I can't figure it out. I have an auto-increment ID column, which counts up in single digits, i.e. 0,1,2,3,4... How do I make it, so it counts up like this: 00001,00002,00003,00004... Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/ Share on other sites More sharing options...
rhodesa Posted August 28, 2009 Share Posted August 28, 2009 you can't force it to have leading zeros in the DB...cus it's an integer and integers don't have leading zeros. but you can add the leading zeros when you display the number: <?php $id = 5; print str_pad($id,5,'0',STR_PAD_LEFT); //or printf('%05d',$id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/#findComment-908481 Share on other sites More sharing options...
PFMaBiSmAd Posted August 28, 2009 Share Posted August 28, 2009 Or start with 10001, 10002, ... Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/#findComment-908490 Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 How do I force it to start at 10001 Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/#findComment-908502 Share on other sites More sharing options...
gassaz Posted August 28, 2009 Share Posted August 28, 2009 Try Using ZeroFill... example: `id` int(5) unsigned zerofill NOT NULL auto_increment Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/#findComment-908652 Share on other sites More sharing options...
ryanwood4 Posted August 28, 2009 Author Share Posted August 28, 2009 That worked a treat! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/172301-solved-5-digit-auto-increment-id/#findComment-908656 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.