Search code examples
phpsqlprefixinvoice

AUTOINCREMENT INVOICE NUMBER WITH PREFIX / PHP and SQL


I would like to generate an auto increment invoice number using prefix.

Digits: 11 Prefix: B

From: B0000000001 to B0000000020.

Is there a easy way to do this in PHP?


Solution

  • This is how you can do in in php.

    $index = 11;
    $prefix = 'B';
    echo sprintf("%s%011s", $prefix, $index);