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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 27, 2007 Share Posted September 27, 2007 LPAD()? Quote Link to comment 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 ?> Quote Link to comment 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. Quote Link to comment 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(). Quote Link to comment Share on other sites More sharing options...
phpknight Posted October 2, 2007 Author Share Posted October 2, 2007 Okay, thanks! Quote Link to comment 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.