Please how can I generate a unique id that increments when a new invoice is created. For example, I have an invoice with the id NR20200001 so the Next invoice created the Id should be NR20200002.
This is my code below, I can't seem to increment the unique id I generated, so I just generated it randomly, but I need to generate it incrementally
<?php
$qry = "SELECT * from requisitions order by req_id desc";
$result = mysqli_query($connection, $qry);
$row = mysqli_fetch_array($result);
$lastid = $row['req_id'];
if($lastid == ""){
$number = "NR".date("Y").date("s");
}
else{
$length=2;
$number = substr($lastid,4);
$number = intval($number);
$number = "NR".date("Y").date("s").substr(str_shuffle(str_repeat($x='0123456789',ceil($length/strlen($x)))),1,$length);
}
?>