Hey all,
I am creating a function that will take in the maximum value from a field in my database. I need to process that string and pass the id into a text field. I need to add leading zeros when appropriate (either 1 or 2 zeros). However, this does not work. I tried to do it with str_pad according to a previous thread in this forum but it did not work for me either. Here's a snippet of my code:
I also looked into sprintf and printf but they output the value and I just need to assign it to something else. Any feedback is welcome. Thanks.
I am creating a function that will take in the maximum value from a field in my database. I need to process that string and pass the id into a text field. I need to add leading zeros when appropriate (either 1 or 2 zeros). However, this does not work. I tried to do it with str_pad according to a previous thread in this forum but it did not work for me either. Here's a snippet of my code:
Code:
$nextOMSID = $omsids[0] + 1;
if(strlen($nextOMSID) == 1)
$nextOMSID = str_pad($nextOMSID, 2, '0', STR_PAD_LEFT);
else if(strlen($nextOMSID) == 2)
$nextOMSID = str_pad($nextOMSID, 1, '0', STR_PAD_LEFT);
else
$nextOMSID = str_pad($nextOMSID, 0, '0', STR_PAD_LEFT);
I also looked into sprintf and printf but they output the value and I just need to assign it to something else. Any feedback is welcome. Thanks.