将详细信息插入子表时,我想从主表中减少该数量。例如,如果主表有10个项目,我通过表单减少6个项目,当我提交它时,主表应该有4个项目。 我的主表是 mainstock ,子表是请求 这是我的代码。
[![<form id="details" action="" method="POST">
<label for="Item">Item</label>
<select id="Item" name="Item">
<option value="item one">One</option>
<option value="item two">Two</option>
<option value="item three">Three</option>
</select>
<label for="Quantity">Quantity</label>
<input type="text" id="Quantity" name="Quantity" placeholder="Enter the Quantity">
<label for="Location">Location</label>
<select id="Location" name="Location">
<option value="item one">One</option>
<option value="item two">Two</option>
<option value="item three">Three</option>
</select>
<label for="FromDate">From</label>
<input <label type="text" id="FromDate" name="FromDate" placeholder="YYYY-MM-DD">
<label for="ToDate">To</label>
<input <label type="text" id="ToDate" name="ToDate" placeholder="YYYY-MM-DD">
<center><button name="submit" type="submit" id="submit">Submit</button>
<button onclick="win();" name="Back" type="back" id="details-back">Back</button></center>
</form>
<!-- INSERT DATA INTO DATABASE -->
<?php
if(isset($_POST\['submit'\])){
$Item = $_POST\['Item'\];
$Quantity = $_POST\['Quantity'\];
$Location = $_POST\['Location'\];
$FromDate = $_POST\['FromDate'\];
$ToDate = $_POST\['ToDate'\];
//Insert Query of SQL
$query = mysql_query("INSERT INTO request(Item,Quantity,Location,FromDate,ToDate) VALUES ('$Item','$Quantity','$Location' ,'$FromDate', '$ToDate')",$connection);
}
?>
<!-- END INSERT DATA INTO DATABASE -->]
答案 0 :(得分:0)
您手头有数量,因此您可以更新主菜:
UPDATE `mainstock` SET `quantity`=`quantity` - '.$Quantity.' WHERE `item`="'.$Item.'"'
答案 1 :(得分:-1)
如果我理解正确,您希望在插入请求表后更新mainStock表中的数量。
为此你可以执行一个选择&amp;更新主表上的查询。
例如=&gt;
//选择查询
import base64
import zlib
data = 'H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA=='
json_str = zlib.decompress(base64.b64decode(data), 16 + zlib.MAX_WBITS).decode('utf-8')
获得当前数量值后,您可以计算剩余数量。
$query = mysql_query("select Quantity from mainstock where Item = '$Item'"),$connection)
//使用更新查询更新主表
$remaining = $current - $Quantity;
希望这会有所帮助:)