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) 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 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. 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. Link to comment https://forums.phpfreaks.com/topic/233680-format-column-mysql/#findComment-1203434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.