0

我有一个 mysql UPDATE 查询:

$updateExpries = "UPDATE table SET 
                   field = '$value'
                   WHERE oneField != '$anotherValue'";

如何获取刚刚更新的所有项目并分别为每个项目更新另一个字段?

4

2 回答 2

1

您可以更新表中的多个字段:

UPDATE table 
SET 
    field = 'value', 
    field2 = 'another value', 
    field3 = 'third value' 
WHERE oneField != 'term'
于 2013-11-03T13:36:35.680 回答
0
if($res = $sqli->query($updateExpries)) {
    while ($row = $res->fetch_assoc()) {
        $fieldFromQuery = $row["someField"];
        $newQuery = "UPDATE table SET newfield = '$fieldFromQuery' WHERE someotherField != '$Valuewhaterver'";
        ...
    }
} else handle error;

或者类似的东西,如果你不使用 sqli

于 2013-11-03T13:43:26.147 回答