phpknight Posted September 27, 2007 Share Posted September 27, 2007 Is there a way to get mysql_insert_id function to return the value with the padding zeros? I am using bigint. Even though I format it explicitly as a strong upon return, it still leaves out the zeros up front. Any ideas? Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/ Share on other sites More sharing options...
phpknight Posted September 27, 2007 Author Share Posted September 27, 2007 I am temporarily doing this by writing my own zerofill function, but there should be something better out there. Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-356269 Share on other sites More sharing options...
fenway Posted September 27, 2007 Share Posted September 27, 2007 LPAD()? Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-356547 Share on other sites More sharing options...
Barand Posted September 29, 2007 Share Posted September 29, 2007 or <?php $num = 42; $padded = sprintf('%08d', $num); // 00000042 ?> Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-358019 Share on other sites More sharing options...
phpknight Posted October 2, 2007 Author Share Posted October 2, 2007 I cannot find the LPAD function. About the sprintf, I was hoping there was actually a function call for it that is like mysql_insert_id() but returns a padded number. The problem is it is truncating my zerofill. I have it working now, so it is no big deal, but it threw me at first. Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-359918 Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 I cannot find the LPAD function. Because you're looking in php, not mysql. And no, there is a function for this... LPAD(). Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-360016 Share on other sites More sharing options...
phpknight Posted October 2, 2007 Author Share Posted October 2, 2007 Okay, thanks! Link to comment https://forums.phpfreaks.com/topic/70864-solved-mysql_insert_id-with-zerofill/#findComment-360335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.