In this code, after insert values to DB.I am doing select query for selecting invoiceNo($sql1= "select invoiceNo from invoices order by invoiceID desc limit 1"; ).Instead of selecting from DB how to get InvoiceNo?

For eg: Assume two users are there.Two users inserts InvoiceID at a same time.While doing "select invoiceNo from invoices order by invoiceID desc limit 1";this will get last coming invoiceID .I need to get specific invoiceID (for particular user) .How to get it?

```
$query          = "select * from invoices order by invoiceID desc limit 1";
$result         = $link->query($query);
$row            = $result->fetch_assoc();
$invoiceNo      = $row["invoiceNo"];
$getinvoiceNo   = str_pad($invoiceNo + 1, 4, 0, STR_PAD_LEFT); //inserting like 0000
$sql            = "INSERT INTO invoices (invoiceNo)
                   VALUES ('$getinvoiceNo')";
if ($link->query($sql) === TRUE) {
   //echo "1";
   $sql1    = "select invoiceNo from invoices order by invoiceID desc limit 1";
   $last_id = mysqli_insert_id($link, $sql1);
   $result1 = mysqli_query($link, $sql1);
   $row1    = mysqli_fetch_array($result1);
   echo json_encode($row1);
} else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysql_close($link);

```