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. 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); ?> 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, ... 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 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 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. 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
Archived
This topic is now archived and is closed to further replies.