我正在写产品库存脚本。我有一个MySQL表“products_stock”:如何从几个MySQL字段中减去一定的值
id zid pid amount
1 123 321 1
2 124 321 5
4 124 566 7
3 125 321 10
所以,在股票产品ID = 321的总量是16.有人为了使具有PID = 321和数量= 7 我需要一些PHP函数,这将减去列量从第一 ZID开始7,并在表中更新记录 products_stock,使其lookes后是这样的:
id zid pid amount
1 123 321 0
2 124 321 0
4 124 566 7
3 125 321 9
我试图做:
function mysql_fields_minus_value ($pid, $amount) {
$q_select_stock_data = "SELECT * FROM `products_stock` WHERE `pid` = '".$pid."'";
$r_select_stock_data = mysql_query($q_select_stock_data);
if (mysql_num_rows($r_select_stock_data)>0) { // First we check if there is such product in stock
// Then we go through all records which have that pid
while ($a_select_stock_data=mysql_fetch_array($r_select_stock_data)) {
// echo "<p>".$a_select_stock_data['stock']."</p>";
$product_pid = $a_select_stock_data['sku'];
$product_qty_order = 7; // qty of pid in order
// than we check if we have enough qtys of product in stock
if ($a_select_stock_data['amount'] - $amount)>=0) { // ok- enough
从这一点我被困住了。
谢谢你的回答!
你能分享你已经尝试过什么,或者你想要的。我们只是为你写出来的吗? – 2014-10-20 21:44:27
请尝试编写你的函数,并在这里发布代码,如果你在某个时刻被卡住了,你的问题对于计算器来说太宽了。 – Ejaz 2014-10-20 21:44:35
我必须同意每一个人这是一个穷人问题,你应该给社会更多的帮助你 – MZaragoza 2014-10-20 21:50:25