简体   繁体   English

mysql更新倍数为什么不起作用? 哦,还php

[英]mysql update multiples why doesn't it work? Oh and php also

I don't understand why this won't work, each line one by one works but not when I join them together... 我不明白为什么这行不通,每一行都一个接一个地起作用,但是当我将它们连接在一起时却不起作用...

mysql_query("
 UPDATE imageProperties
  SET value='98' WHERE element='img1' AND property='left';
  SET value='67' WHERE element='img1' AND property='top';
  SET value='15' WHERE element='img1' AND property='width';
  SET value='15' WHERE element='img1' AND property='height';
  SET value='22' WHERE element='img2' AND property='left';
  SET value='49' WHERE element='img2' AND property='top';
  SET value='62' WHERE element='img2' AND property='width';
  SET value='75' WHERE element='img2' AND property='height';
");

I got the idea from the answer to this question here 我从答案的想法,这个问题在这里

syntax is wrong.you should have UPDATE imageProperties for each set: 语法错误。每个集合都应具有UPDATE imageProperties:

UPDATE imageProperties
  SET value='98' WHERE element='img1' AND property='left';
UPDATE imageProperties
  SET value='67' WHERE element='img1' AND property='top';
UPDATE imageProperties
  SET value='15' WHERE element='img1' AND property='width';

try it by using CASE statment in one statment. 在一则陈述中使用CASE陈述来尝试一下。

   UPDATE imageProperties
   SET value= CASE when element='img1' AND property='left'   then '98' 
                   when element='img1' AND property='top'    then '67'
                   when element='img1' AND property='width'  then '15'
                   when element='img1' AND property='height' then '15'
                   when element='img2' AND property='left'   then '22'
                   when element='img2' AND property='top'    then '49'
                   when element='img2' AND property='width'  then '62'
                   when element='img2' AND property='height' then '75'
               ELSE `value`
               END

You are terminating the statement with each semicolon. 您将用每个分号终止该语句。

This should work: 这应该工作:

mysql_query("
 UPDATE imageProperties
  SET value='98' WHERE element='img1' AND property='left';
 UPDATE imageProperties
  SET value='67' WHERE element='img1' AND property='top';
 UPDATE imageProperties
  SET value='15' WHERE element='img1' AND property='width';
 UPDATE imageProperties
  SET value='15' WHERE element='img1' AND property='height';
 UPDATE imageProperties
  SET value='22' WHERE element='img2' AND property='left';
 UPDATE imageProperties
  SET value='49' WHERE element='img2' AND property='top';
 UPDATE imageProperties
  SET value='62' WHERE element='img2' AND property='width';
 UPDATE imageProperties
  SET value='75' WHERE element='img2' AND property='height';
");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM