Bickey Posted April 14, 2011 Share Posted April 14, 2011 In my MYSQL db how do I format a single or two digit number to have 0 in front? (e.g. 005, 012) Quote Link to comment https://forums.phpfreaks.com/topic/233680-format-column-mysql/ Share on other sites More sharing options...
requinix Posted April 14, 2011 Share Posted April 14, 2011 Do it in PHP, not MySQL. printf("%03u", 12); // to print/echo it $number = sprintf("%03u", 12); // to get the value Quote Link to comment https://forums.phpfreaks.com/topic/233680-format-column-mysql/#findComment-1201435 Share on other sites More sharing options...
Muddy_Funster Posted April 14, 2011 Share Posted April 14, 2011 Or, to do it in MySQL, set the column type to be INT (3) UNSIGNED ZEROFILL and your done. Quote Link to comment https://forums.phpfreaks.com/topic/233680-format-column-mysql/#findComment-1201625 Share on other sites More sharing options...
fenway Posted April 19, 2011 Share Posted April 19, 2011 Or, to do it in MySQL, set the column type to be INT (3) UNSIGNED ZEROFILL and your done. Please don't store formatting the in the DB -- as tempting is it may be. Quote Link to comment https://forums.phpfreaks.com/topic/233680-format-column-mysql/#findComment-1203434 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.