php mysqli,如何选择值并准备更新其他表

时间:2015-12-05 21:08:31

标签: php mysql mysqli

我有一个mysqli查询,代码如下:

    $stmt = $mysqli->prepare('SELECT `user`, `status` FROM `mytable1` WHERE `type`=?');
    $type = 1;
    $stmt->bind_param('i', $type);
    $stmt->execute();
    $stmt->bind_result($user, $status);
    $stmt->store_result();
    $stmt->fetch();
    $stmt->close();

我需要更新专栏" Money"用户有类型" 1"来自" mytable1"

$stmt = $mysqli->prepare('UPDATE `mytable2` SET `money`=100 WHERE `user`=?');
$stmt->bind_param('s', $user);
$stmt->execute();
$stmt->close();

这样只更新一个用户。 我找到了PHP文档,但没有例子:(

1 个答案:

答案 0 :(得分:0)

也许这样的组合查询:

UPDATE `mytable2` SET `money`=100 WHERE `user` in (
SELECT distinct `user` FROM `mytable1` WHERE `type`=?'
);