Generate invoice number from 0 to so on for ordered products in orders table in php mysqli
Okay, As per our discussion, what you want is
the same invoice number to, one order(one order can have multiple products but from one User).

So I think you need one table which can save the Invoice Number So when you are inserting into order table before that you fetch the Invoice Number and increment it, then you in order table

$INV_NUM = "SELECT INVOICE_NUMBER FROM INVOICE";
$INV_NUM++;

$squery = "SELECT * FROM cart WHERE user_id = '$user_id'";
$sresult = $this-&gt;db-&gt;select($squery);
if($sresult){
    $totalPrice = 0;
    $i = 0;
    while($svalue = $sresult-&gt;fetch_assoc()){
....................
....................
....................
 $query = "INSERT INTO orders(user_id, pro_id, invoice_no, pro_name, status, date) "
                . "VALUES('$user_id', '$pro_id', '$INV_NUM', '$pro_name', 'processing', NOW())";
....................
....................


This strategy might help you. Please let me know, it works or not?