gpt4 book ai didi

php - 处理空值和 JSON

转载 作者:行者123 更新时间:2023-11-29 03:43:18 24 4
gpt4 key购买 nike

我正在尝试使用 IFNULL() 函数来防止查询结果为空, 因为当结果转换为 JSON 数组时,空值会导致错误。

$sql = mysql_query("select IFNULL(status,'nothing'),
foodname from disease_food,
food where disease_food.Disease_ID=$d1 or disease_food.Disease_ID=$d2 and
Food_ID=$res1 and disease_food.Food_ID=food.ID");

while($row=mysql_fetch_assoc($sql)) {
$output[] = $row;
}

$data = json_encode($output);
print($data);
mysql_close();

错误:(当结果为空时)

undefined variable :输出

最佳答案

我觉得你打错了。状态前有一个 ' 缺失。

   IFNULL(status,'nothing')

关于php - 处理空值和 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395629/

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