auto fill characters in product ID

Hi

i hope someone can help me please?

I have a mysql database with product ID’s.
the ID’s are always 8 characters long (example - NZL01254)

the issue is that the record Id’s reflect the same code but without NZL and the leading 0’s

so when i click on a product link i have ?PID=123 when it should be ?PID=NZL00123
sometimes the code is NZL00012 or NZL01234

the above are example codes.
the actual codes range from 1 - 2767

So my question is can i please have a piece of code that will read the record ID’s and then insert the NZL and the right amount of 0’s after the NZL so the whole product ID is 8 characters long?

Thanks in advance
Peter

Bump.
Can i do that?

can anyone help?

Well, there is many many ways to do this. First, PHP doesn’t really care if it is a number or string.
PHP auto-types variables unless you tell it what you want it to be. Any variable is $variablename, etc…

So, you can just use strings to create your needed results.
Something like this might work…

$pid=123; // Create an INTEGER variable (auto-types to int)
$temp=“NZL00000”; // Create a base to work with (auto-types to string)
$results=substr($temp, 0, 8-len($pid)) . $pid; // Takes the NZL00000 less the length of the actual pid

I did not test this, but, something like it should work for you… Good luck…

Hi

i see what you mean, thanks. will give it a bash this weekend.
Will post if having hassles :slight_smile:

Thank you heaps :slight_smile:

It should work as long as the format never changes… GOOD luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service