php - mysql update qty on complete order array -


this question has answer here:

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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -