php和mysql中的双重查询 [英] double query in php and mysql
问题描述
我有一个简单的INSERT查询,它在事件点击按钮时运行,它获取变量并将它们插入到`order`表中。
我也会喜欢更新我的乐队表格,将股票减少1直到达到0然后显示空或售罄而不是进入负数例如:-6
知道什么乐队被选中我可以使用:
I have a simple INSERT query that is run on event click of a button, this gets variables and inserts them into `order` table.
I also would like to UPDATE my bands table to reduce the stock by 1 until it reaches 0 then show null or sold out rather than go into negative eg: -6
to know what band is selected I can use :
WHERE Band_id = $Band_id");
在同一声明中。
目前的INSERT看起来像:
in the same statement.
the current INSERT looks like :
"INSERT INTO orders (band_id,user_id,user_name,band_name,band_venue) VALUES('$Band_id', '$user_id', '$user_name', '$name', '$venue')";
**结论* *
需要改变我的INSERT以更新WHILE检查它当前选择的乐队。
**答案提供检查**
这个解决方案有提供得非常好而且很有意义,但我还不够熟练,无法理解为什么它不能正常运行。
**Conclusion**
Need to alter my INSERT to also UPDATE WHILE checking that its the current selected band.
**ANSWER PROVIDED CHECK**
this solution has been wonderfully provided and it makes sense but im not quite skilled enough to understand why its not functioning correctly.
$sql = "INSERT INTO orders (band_id,user_id,user_name,band_name,band_venue) VALUES('$Band_id', '$user_id', '$user_name', '$name', '$venue')";
$sql_create ="CREATE TRIGGER tg_ai_orders
AFTER INSERT ON orders
FOR EACH ROW
UPDATE bands
SET stock = stock - 1
WHERE band_id = NEW.band_id";
$sql_deleat = "CREATE TRIGGER tg_ad_orders
AFTER DELETE ON orders
FOR EACH ROW
UPDATE bands
SET stock = stock + 1
WHERE band_id = OLD.band_id";
mysql_query ($sql, $sql_deleat, $sql_create, $linkme)
or die ("could not add to database");
推荐答案
Band_id );
Band_id");
在同一声明中。
当前的INSERT如下:
in the same statement.
the current INSERT looks like :
"INSERT INTO orders (band_id,user_id,user_name,band_name,band_venue) VALUES('
Band_id','
Band_id', '
user_id','
user_id', '
这篇关于php和mysql中的双重查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!