我正在从数据库中获取值并将其转换为 json 对象。它工作正常,但问题是如果值为空白(未分配“null”值),它在 json 输出中显示为 null。我尝试了 if 条件来检查它,如果值为空则跳过它。但它不起作用。对于 if 条件,我该怎么办,以便如果值为空白,它应该跳过那个。请提出一些解决方案。我是php的新手
<?php
$connect = mysql_connect("localhost","plinlt","lajisdfla");
mysql_select_db("plinlt");
$result = mysql_query("SELECT field_id_6 FROM exp_channel_data") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["events"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
if($row["field_id_6"]==null)
{
Echo "";
}
else
{
$product["event"] = $row["field_id_6"];
// push single product into final response array
array_push($response["events"], $product);
}
}
// success
$response["success"] = 1;
$preserved = array_reverse($response, true);
// echoing JSON response
echo json_encode($preserved);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>