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 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. 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. 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; } ?> 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; 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 Link to comment https://forums.phpfreaks.com/topic/50279-solved-id-count-type/#findComment-249962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.