我有以下查询:
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脚本,它必须实际向用户发送一封电子邮件我更新硬币数量。电子邮件字段位于用户表中。
谢谢!
答案 0 :(得分: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循环中的每一行,您也可以发送邮件。
<强>更新强>
因此,假设$result
是带结果数组的var。
foreach($result as $res){
$sql = 'UPDATE users SET coins = coins+200 WHERE id = '.$res['id'];
mail(/*WITH YOUR PARAMS*/); //email in $res['email'];
}