0

我有以下查询:

UPDATE
    users AS t
    LEFT JOIN (
        SELECT
          user
        FROM
               facebook, users
        WHERE
            facebook.user = users.id
        GROUP BY
           users.id
    ) AS m ON
        m.user = t.id
SET
   t.coins =t.coins+200
WHERE
  m.user = t.id

我需要帮助来创建一个 php 脚本,该脚本必须实际向我更新硬币数量的用户发送电子邮件。电子邮件字段在用户表中。

谢谢!

4

1 回答 1

1

选择您需要的所有行:

SELECT
t.id, t.email
FROM
    users AS t
    LEFT JOIN (
        SELECT
          user
        FROM
               facebook, users
        WHERE
            facebook.user = users.id
        GROUP BY
           users.id
    ) AS m ON
        m.user = t.id
WHERE
  m.user = t.id

然后更新 PHP 循环中的每一行,您也可以在其中发送邮件。

更新

所以让我们想象一下$resultvar 和结果数组。

foreach($result as $res){
    $sql = 'UPDATE users SET coins = coins+200 WHERE id = '.$res['id'];
    mail(/*WITH YOUR PARAMS*/); //email in $res['email'];
}
于 2013-04-04T12:23:53.293 回答