php - mysql update qty on complete order array -
this question has answer here:
- mysql update table ajax class 1 answer
i'm trying update quantities left in stock on items in order, when order completed in point of sale system
my code far is
$order=$_get["order"]; include('php/config.php'); $invoice=$order; $voucher=$_get['voucher']; $card=$_get['card']; $cash=$_get["cash"]; $date = date('y-m-d'); $sql="select * `orders` `invoice` = '".$invoice."'"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $parts[] = array( "part" => $row['part'], "qty" => $row['qty'], ); $sqlstock = "update `stock` set available='available - $parts[qty]' part = '".$parts['part']."'"; }
probably best single piece of sql:-
update stock inner join order b on a.part = b.part set a.available = a.available - b.qty b.invoice` = '$order'
watch out don't rerun multiple times without way of checking order hasn't been used update stock
doing way, if had 1000 items on order single query. doing select , looping around results require 10001 queries.
Comments
Post a Comment