cmaclennan Posted May 19, 2009 Share Posted May 19, 2009 Hi Guys, I am wondering if there is a way to save the preceding zeroes of an ID? I have the field set to auto increment and can display them with the preceding zeroes using zerofil however when i pass the id to another page it passes with the zeroes and comes as an invalid id as the zeroes arent saved in the database, any help would be much appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/ Share on other sites More sharing options...
fenway Posted May 19, 2009 Share Posted May 19, 2009 You can, but you don't want to... simply format the ID however you'd like on output. Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837371 Share on other sites More sharing options...
cmaclennan Posted May 19, 2009 Author Share Posted May 19, 2009 Not Sure I understand completely I'm still a bit of a novice with some of this stuff, do you mean i should just strip the zeroes when passing the ID? And if so how would I go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837377 Share on other sites More sharing options...
fenway Posted May 19, 2009 Share Posted May 19, 2009 I'm saying don't use ZEROFILL... use LPAD() whenever you want to format your ID. Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837386 Share on other sites More sharing options...
jackpf Posted May 19, 2009 Share Posted May 19, 2009 Can't you just not using preceeding zeros? Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837389 Share on other sites More sharing options...
cmaclennan Posted May 19, 2009 Author Share Posted May 19, 2009 I'd love to not use the precedding zeroes however it is required for this task, and how would i insert something like LPAD () into an existing query? or would it be seperate? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837392 Share on other sites More sharing options...
jackpf Posted May 19, 2009 Share Posted May 19, 2009 If you have a text or varchar field it should preserve zeros. Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837397 Share on other sites More sharing options...
cmaclennan Posted May 19, 2009 Author Share Posted May 19, 2009 I can't use a text or varchar field as its an auto_incrementing PK Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837398 Share on other sites More sharing options...
PFMaBiSmAd Posted May 19, 2009 Share Posted May 19, 2009 You are way over complicating this. Keep the value as a number every place except when you display it. Only when you display it should you add the leading zeros. Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837399 Share on other sites More sharing options...
cmaclennan Posted May 19, 2009 Author Share Posted May 19, 2009 Thats all I'm trying to do, Im just not sure how to use the LPAD function in my existing query or how to go about formatting it to display the preceeding zero's Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837400 Share on other sites More sharing options...
fenway Posted May 19, 2009 Share Posted May 19, 2009 Thats all I'm trying to do, Im just not sure how to use the LPAD function in my existing query or how to go about formatting it to display the preceeding zero's Then take a quite peek at the refman.... Quote Link to comment https://forums.phpfreaks.com/topic/158769-solved-is-it-possible-to-save-leading-zeroes-in-database/#findComment-837433 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.