我希望根据表格中输入的数字添加和减去数字。
这是我的代码:
$uratio = "
UPDATE teams
LEFT JOIN games g1 ON (teams.ID = g1.op1ID)
SET ratio = ratio
+ IF(g1.op1gamescore = 1 , g1.op1score, g1.op1score)
, ratio = ratio
- IF(g1.op1gamescore = 0, g1.op1score, g1.op1score)
WHERE g1.ID = '$_POST[id]' ;
";
mysql_query($uratio) or die (mysql_error());
$uratiob = "
UPDATE teams
LEFT JOIN games g2 ON (teams.ID = g2.op2ID)
SET ratio = ratio
+ IF(g2.op2gamescore = 1, g2.op2score, g2.op2score)
, ratio = ratio
- IF(g2.op2gamescore = 0, g2.op2score, g2.op2score)
WHERE g2.ID = '$_POST[id]' ;
";
mysql_query($uratiob) or die (mysql_error());
当op2gamescore = 1时,它将op1设为(负号),而op2设置为(负号)op2是正常但op1不是。
当op1gamescore = 1时,它会做同样的事情。
当op1或op2 = 0时,它会校正数学运算。但不是当它等于1.
它做正确的数学但是op1总是以负号结束,为什么呢?它就像是执行 - 如果不是+ IF ...任何想法?
答案 0 :(得分:0)
查询1:
UPDATE
teams
LEFT JOIN
games
ON
teams.ID = games.op1ID
SET
ratio = ratio + IF(games.op1gamescore = 1, games.op1score, -1 * games.op1score)
查询2:
UPDATE
teams
LEFT JOIN
games
ON
teams.ID = games.op2ID
SET
ratio = ratio + IF(games.op2gamescore = 1, games.op2score, -1 * games.op2score)