I wonder if it's possible to create a primary key, aaa-0000 as a mask, and still be auto_increment
, example aaa-0000, aaaa-0001, and so on.
If so, how?
Thank you
I wonder if it's possible to create a primary key, aaa-0000 as a mask, and still be auto_increment
, example aaa-0000, aaaa-0001, and so on.
If so, how?
Thank you
Apply the mask at the time of the display.
$db = [conexao e leitura do banco];
foreach ($db as $v) {
//iterando os dados extraídos do banco
echo 'aaa-'.str_pad($v['id'], 4, '0', STR_PAD_LEFT).PHP_EOL;
}
(the above code is didactic, with illustrative purpose)
output:
id 1 will display: aaa-0001
id 10 will show: aaa-0010
id 100 will show: aaa-0100
See: str_pad ()