|
Posted by muldoonaz on 09/09/05 01:19
yellow1912 wrote:
> Big thanks guys!
> But what if the field must be string, and I cant really control what
> user input?
> They can input Item 1, or Item 01, .... There's no way ?
>
you can control what you put in the db though. There's a php function
that'll float the number to any given number of leading 0's.
I wrote some code that helps me move things around in my knowledge base
when incidents or articles are added.
$code = "FF00512"; // KB code, pulled from the end of the table
$prefix = substr($code,0,2); // output: "FF"
$suffix = substr($code,2,5)+1; // "00512" + 1, output: "513"
$suffix = sprintf("%05d", $suffix); // output: "00513"
$solutionid = $prefix.$suffix; // combine the prefix and the suffix
echo $solutionid; // output: "FF00513"
you could change the %05d to %03d, it'll make sure the integer is 3
numbers long and add leading zero's until it matches that. %05d will be
5 numbers, %07d 7 numbers and so on...
im sure there are easier ways to do this, but this was my solution.
Navigation:
[Reply to this message]
|