Bah, I hate Monday mornings!
Well the only thing we can guarantee that would be unique at the time of record creation would be the id value returned by the database.
Bearing this in mind, I guess we could use that, what about...
PHP Code:
<?php
function generateCode($iId)
{
$aKey = range('A', 'J');
$sCode = '';
preg_match_all('~[0-9]~', sprintf('%06d', $iId), $aMatches);
foreach(array_shift($aMatches) as $iValue)
{
$sCode .= $aKey[(int)$iValue];
}
return $sCode;
}
echo generateCode(1); #AAAAAB
echo generateCode(000001); #AAAAAB
echo generateCode(435355); #EDFDFF
echo generateCode(756356); #HFGDFG
echo generateCode(867453); #IGHEFD
echo generateCode(9444); #AAJEEE
echo generateCode(5389); #AAFDIJ
?>
It's early, so you'll have to forgive the sloppy code.
Bookmarks