MYSQL primary key is it possible to create an AUTO_INCREMENT fill mask?

Asked

Viewed 93 times

2

I wonder if it is possible to create a primary key, aaa-0000 as a mask and still be auto_increment, aaa-0000, aaaa-0001, so on. If yes, how to do?

Thank you

1 answer

1


Apply the mask when displaying.

$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 show: aaa-0001
id 10 will show: aaa-0010
id 100 will show: aaa-0100

Consult: str_pad()

  • Thanks so much, I’m taking the test

Browser other questions tagged

You are not signed in. Login or sign up in order to post.