我正在将名为allCooks
的表格中的2行移动到名为recipeChallenge
的表格中的一行(在披萨挑战中对cookBBB的cookAAA)
每个匹配都有一个ID,这是我要更新的行
我正在进行两次更新,一次是cookAAA,另一次是cookBBB 要用cook A更新matchID ...(我已经将php变量留在了)
"UPDATE `recipeChallenge` AS v1,
`allCooks` AS v2
SET v1.`cookAAAID` = v2.`cookID`,
v1.`cookAAAName` = v2.`cookName`
WHERE v1.`matchID`='" .$matchID."'
AND v2.`cookID`= '" .$cookAID."'";
然后是厨师B
"UPDATE `recipeChallenge` AS v1,
`allCooks` AS v2
SET v1.`cookBBBID` = v2.`cookID`,
v1.`cookBBBName` = v2.`cookName`
WHERE v1.`matchID`='" .$matchID."'
AND v2.`cookID`= '" .$cookBID."'";
表recipeChallenge
正在更新,但第二次更新还是在matchID
表格中创建新的recipeChallenge
和行。为什么?
答案 0 :(得分:1)
你可以这样做:
"UPDATE `recipeChallenge` AS v1,
`allCooks` AS v2 ,
`allCooks` AS v3
SET v1.`cookAAAID` = v2.`cookID`,
v1.`cookAAAName` = v2.`cookName`,
v1.`cookBBBID` = v3.`cookID`,
v1.`cookBBBName` = v3.`cookName`
WHERE v1.`matchID`='" .$matchID."'
AND v2.`cookID`= '" .$cookAID."'
AND v3.`cookID`= '" .$cookBID."'";