eRott Posted May 9, 2009 Share Posted May 9, 2009 Hey, Quick question. I have some values being written to a field in a database. Sometimes those values are just two zero's (00). I have the field type set as int(2). However, MySQL just rewrites those two zeros as a single zero (0). I need those two zeros to remain intact. Is there a way to stick with the int field type but leave the data written to that field as is? Thanks. Link to comment https://forums.phpfreaks.com/topic/157449-mysql-table-type/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 9, 2009 Share Posted May 9, 2009 You can use sprintf to format your data before display them http://www.php.net/manual/en/function.sprintf.php Probably like that : $integer = 0; $string = sprintf("%02d", $integer); echo $string; Link to comment https://forums.phpfreaks.com/topic/157449-mysql-table-type/#findComment-830193 Share on other sites More sharing options...
Mchl Posted May 9, 2009 Share Posted May 9, 2009 If 0 and 00 are two different values for you application (hm.... Las Vegas Roulette?), you should use CHAR(2) instead. About INT(n) syntax read here: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html (Just below first table) Link to comment https://forums.phpfreaks.com/topic/157449-mysql-table-type/#findComment-830216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.