This is my php script that selects everything from invoiceNo where invoiceNo is different.
<?php require 'init.php'; $query = 'SELECT * FROM `selected_items` WHERE invoiceNo IN ( SELECT DISTINCT ( invoiceNo) AS invoiceNo FROM selected_items ) GROUP BY invoiceNo;'; $res = mysqli_query($con, $query); $result = []; while ($row = mysqli_fetch_array($res)) { array_push($result, [ 'custInfo' => $row[0], 'invoiceNo' => $row[1], 'barcode' => $row[2], 'description' => $row[3], 'weight' => $row[4], 'rate' => $row[5], 'makingAmt' => $row[6], 'net_rate' => $row[7], 'itemTotal' => $row[8], 'vat' => $row[9], 'sum_total' => $row[10], 'bill_type' => $row[11], 'date' => $row[12], 'advance' => $row[13], 'balance' => $row[14], ]); } echo json_encode(['result' => $result]); mysqli_close($con);

Right now this script is giving me the first value from sum_total, that is, it is giving me the first row from my database, how can I get the last row. I am new to programming any suggestions or help. Thanks:)
user3848444
source share