I have 3 table
package,item,items
table item use to store item information
--------------------------------------
item id|item name|item stock|item used
--------------------------------------
1 | item1 | 100 | 0
2 | item2 | 100 | 0
table package is use to store group item with same package?
--------------------------
package id | package name
--------------------------
1 | package 1
table items is use to store item quantity for each package
----------------------------------------------------
items id|item name|items quantity|item id|package id
----------------------------------------------------
1 | item1 | 20 | 1 | 1
2 | item2 | 40 | 2 | 1
Then if package 1 selected ,I need to Update the item stock and item used in table item
In PHP SELECT query I try this query :
$sql1 = "SELECT items.items_id, items.item_name, items.items_quantity,
item.item_stock, item.item_used
FROM items
INNER JOIN item ON item.item_name = items.item_name
WHERE items.package_id = '1' ";
$txtquery = mysqli_query($con,$sql1);
while($row = mysqli_fetch_assoc($txtquery)){
//this for single item only
$items_quantity=$row['items_quantity'];
$item_name=$row['item_name'];
$sql2="Update item
SET item_stock=item_stock-'$items_quantity',
item_used=item_used+'$items_quantity'
WHERE item_name='$item_name'";
$query = mysqli_query($con,$sql2);
}
When sql1 query run, will show for this table
----------------------------------------------------
items id|item name|items quantity|item stock|item used
----------------------------------------------------
1 | item1 | 20 | 100 | 0
2 | item2 | 40 | 100 | 0
*when update i need get the result like this :
------------------------------------------------------------
items id|item name |items quantity |item stock |item used
------------------------------------------------------------
1 | item1 | 20 | 80 | 20
2 | item2 | 40 | 60 | 40
item stock = item stock - items quantity
item used = item used + item_quantity
But I no idea for how to update the Item stock and item used with multiple item in the row