为什么我的代码不更新?
并回显否!
$sql_updata1 = "UPDATE information_user SET invitation = '1' WHERE information_user.id = '$ID_Invitation'; UPDATE information_user SET valid = '$num_Invitation '+' $number_userInvitation' WHERE information_user.id = '$ID_Invitation'; UPDATE information_user SET valid = '$num_Caller '+' $number_userCaller' WHERE information_user.id = '$id_user_invitation';";
if ((mysqli_query($con, $sql_updata1)){
echo "ok";
} else {
echo "no";
}
答案 0 :(得分:1)
您可以将其作为单个查询来执行。使WHERE
子句同时选择呼叫者和被呼叫者。您可以在SET
子句中分配多个列,并且可以使用IF
或CASE
使分配的值取决于行的id
重新处理。
$sql_updata1 = "
UPDATE information_user
SET invitation = IF(id = '$ID_Invitation', '1', invitation)
valid = IF(id = '$ID_Invitation',
$num_Invitation + $number_userInvitation,
$num_Caller + $number_userCaller)
WHERE id IN ('$ID_Invitation', '$id_user_invitation')";