gpt4 book ai didi

php - if 和 else 语句都在执行

转载 作者:可可西里 更新时间:2023-10-31 23:55:00 25 4
gpt4 key购买 nike

我遇到了一个奇怪的问题:我的 if 和 else 语句都在执行。这是我的代码:

    if ($sel_user['name'] != $name) {
$query = "UPDATE owner SET
..."
$result = mysql_query($query);
if (mysql_affected_rows() ==1) {
$query2 = "UPDATE queue_acl SET
..."
$result2 = mysql_query($query2);
if (mysql_affected_rows() ==1) {
$_SESSION['updates_occurred'] = true;
} else {
$_SESSION['updates_occurred'] = false;
}
}
}

if ($sel_user['orgId'] != $orgId) {
$query = "UPDATE ownerOrganization SET
..."
$result = mysql_query($query);
if (mysql_affected_rows() ==1) {
$query2 = "UPDATE queue_acl SET
..."
$result2 = mysql_query($query2);
if (mysql_affected_rows() ==1) {
$_SESSION['updates_occurred'] = true;
} else {
$_SESSION['updates_occurred'] = false;
}
}
}

if ($sel_user['date_expires'] != $colVal[0] ||
$sel_user['admin'] != $colVal[4]) {
$query3 = "UPDATE queue_acl SET
..."
$result3 = mysql_query($query3);
if (mysql_affected_rows() ==1){
$_SESSION['updates_occurred'] = true;
} else {
$_SESSION['updates_occurred'] = false;
}
} else {
$_SESSION['updates_occurred'] = false;
$message = "<i>There were no edits to apply</i>";
}

当我运行它时,正在发送查询并且一切都在正常更新,但也正在打印“没有编辑”消息

有人知道为什么吗?

编辑:我不想使用 elseif 语句;这些事件并不相互排斥。也就是说,如果 $sel_user['name'] != $name AND $sel_user['orgId'] != $orgId,则需要发送两个查询

最佳答案

如果您不想将所有内容都包装在 if/else if 语句中,可以在每个 if 检查的末尾设置一个标志。

if($sel_user['name'] != $name) {
// CODE HERE
$flag = true;
}

if(!$flag){
$message = "<i>There were no edits to apply</i>";
}

就是这样,或者您可以运行 if 检查 $_SESSION['updates_occurred']

关于php - if 和 else 语句都在执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11018001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com