adzie Posted May 6, 2007 Share Posted May 6, 2007 Is there a way to make my id field which is auto increment start with 000001 and upwards as I can only get it to display the number 1 in the field? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 7, 2007 Share Posted May 7, 2007 I do not quite understand - maybe set the column to zerofill. Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-246934 Share on other sites More sharing options...
fenway Posted May 7, 2007 Share Posted May 7, 2007 Don't do that -- format it on output if you care, leave the DB column out of it. Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-247272 Share on other sites More sharing options...
cmgmyr Posted May 7, 2007 Share Posted May 7, 2007 try this: <?php $userid = 1; echo fill($userid,6); function fill($val,$properlen){ $i=0; $l=strlen($val); $properlen = $properlen - $l; $tmpstr=$val; while ($i<$properlen) { $tmpstr="0$tmpstr"; ++$i; } return $tmpstr; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-247278 Share on other sites More sharing options...
bubblegum.anarchy Posted May 8, 2007 Share Posted May 8, 2007 SELECT lpad(id, 6, 0) AS id FROM table; Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-247734 Share on other sites More sharing options...
adzie Posted May 10, 2007 Author Share Posted May 10, 2007 count this as solved thankyou Quote Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-249962 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.