$check_empty_user = $DBcon->query("SELECT * FROM bubble_spends where a_amount <= 0");
$count=$check_empty_user->num_rows;
$username23=$DBcon->query("SELECT a_name FROM bubble_spends where a_amount <= 0 LIMIT 1");
$count2=$username23->fetch_array;
if (!$count==0) {
$DBcon->query("DELETE FROM bubble_spends where a_amount <= 0");
$DBcon->query("UPDATE users SET credits = credits+100000 WHERE username='$count2'");
echo "user has been outspended";
}
主要目标是通过它来实现,当bubble_spend的数量小于0时,它应该从冒泡花费中选择a_name,然后更新用户set credits = credits + 10 where username = $ a_name
但这不起作用,我忙于这个2个小时,我无法得到修复
答案 0 :(得分:0)
您正在尝试在bubble_spends表中获取数量少于0的所有用户,然后从该表执行删除并在另一个表上进行更新。
要以简单的方式执行此操作,请从bubble_spends表中获取所有小于0的名称,然后使用IN运算符和内部查询来更新它们。更新后,您最好从其他表中删除它们。
$DBcon->query("UPDATE users SET credits = credits+100000
WHERE username IN (SELECT a_name FROM bubble_spends where a_amount <= 0)");
$DBcon->query("DELETE FROM bubble_spends where a_amount <= 0");
这应该这样做。