发票编号中添加一个最多10个,然后停止

im having a strange problem, I am using the following script to pull the last invoice number from the database and then add a 1 to it, this works just fine......until you get to 10 invoices, then for some odd reason I just keep getting 10 as the invoice number over and over again.

      <?php 
    $sqlinv = <<<SQL
       SELECT MAX(invoiceID) AS maxId FROM `sales`
    SQL;
    if(!$resultinv = $db->query($sqlinv)){ die('There was an error running the query [' . $db->error . ']');}

    while($rowinv = $resultinv->fetch_assoc()){ 
    $previousinvoiceID = $rowinv['maxId'];
    }
    $invoiceID = $previousinvoiceID +1; 
    echo $previousinvoiceID;
    echo $invoiceID;
    ?>

$previousinvoiceID echos out as 9 $invoiceID echos out as 10 If I delete a few records it works again just fine, but as soon as it gets to 10 it starts repeating 10 again, its as though it treats 9 as the highest number all the time.