开发者

UPDATE leftjoin SET +/- problem

开发者 https://www.devze.com 2023-03-20 04:36 出处:网络
I want numbers to be added and subtracted according to one number entered in the table. Here is my code:

I want numbers to be added and subtracted according to one number entered in the table.

Here is my code:

  $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());   

When op2gamescore = 1 it puts op1 with (negative sign) and op2 with (negative sign) op2 is fine but op1 not.

When op1gamescore = 1 it does the same.

It does correct math when op1 or op2 = 0 . But not when it equlas 1.

It does the correct math but op1 always ends with negative sign, why is that? It开发者_Go百科s like if it executes - IF and not + IF... ANY IDEAS?


query 1:

UPDATE 
  teams 
LEFT JOIN 
  games 
ON
  teams.ID = games.op1ID
SET
  ratio = ratio + IF(games.op1gamescore = 1, games.op1score, -1 * games.op1score)

query 2:

UPDATE 
  teams 
LEFT JOIN 
  games 
ON
  teams.ID = games.op2ID
SET
  ratio = ratio + IF(games.op2gamescore = 1, games.op2score, -1 * games.op2score)
0

精彩评论

暂无评论...
验证码 换一张
取 消