gpt4 book ai didi

php - 对 UPDATE into 的 else 语句有问题

转载 作者:行者123 更新时间:2023-11-29 02:56:44 24 4
gpt4 key购买 nike

这是我正在尝试使用的 if 语句

if ($rows['business_type'] = "Restaurant") {
$table_name = "restaurants";

}

else if ($rows['business_type'] = "Shop") {
$table_name = "shopping";

}

我有一个基于该变量的 isert:

$updatesql = sprintf("UPDATE $table_name SET

如果我用有效的文本($table_name = "shopping')定义变量。如果我只是使用

if ($rows['business_type'] = "shopping"){
$table_name = "shopping";
}

行得通。只有当我尝试使用它不插入的 else 语句时。无论如何,它只是直接插入第一个。

谁能看出我做错了什么。

最佳答案

检查相等性时至少需要==。你有 = 这是赋值。

if ($rows['business_type'] === "Restaurant") {
$table_name = "restaurants";
} else if ($rows['business_type'] === "Shop") {
$table_name = "shopping";
}

关于php - 对 UPDATE into 的 else 语句有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30006098/

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