Código
$recordLastSale = $sale->getLastSale();
Código
$sale = new Sale(); $sale->saveSale(); $recordLastSale = $sale->getLastSale(); $resultLastSale = $recordLastSale->fetch_object(); $idsale = $resultLastSale->last; foreach ($_SESSION['detalle'] as $detail): $idproduct = $detail['idproduct']; $amount = $detail['amount'] ; $price = $detail['price']; $subtotal = $detail['subtotal']; if($sale->saveSaleDetail($idsale,$idproduct,$amount,$price,$subtotal)){ $_SESSION['detalle'][] = $detail; echo "success"; }else{ echo "something went wrong"; } endforeach; }
Código
function saveSale(){ $sql = "INSERT INTO sales(dates) values(NOW())"; $result = $this->conexion->conexion->query($sql); return $result; $this->conexion->conectar(); } function getLastSale(){ $sql = "SELECT LAST_INSERT_ID() AS last"; $result = $this->conexion->conexion->query($sql); return $result; $this->conexion->conectar(); } function saveSaleDetail($idsale,$idproduct,$amount,$price,$subtotal){ $sql = "INSERT INTO sale_detail(idsale,idproduct,amount,price,subtotal) VALUES('$idsale','$idproduct','$amount','$price','$subtotal')"; $result = $this->conexion->conexion->query($sql); return $result; $this->conexion->conectar(); }