I have a WebService in PHP that returns me a JSON with values from a mySQL database.
I need an Array, whenever there is a null value (when = null
), is changed to white ( = ""
).
I'm doing it this way, but without success.
<?php
header("Content-Type: application/json; charset=utf-8;");
include('connectdb.php');
$something = $_GET['cod'];
$sqlcode = mysql_query("Select descricao, cliente, local from terminal_cartao Where descricao='$something'");
$sqlcode2 = mysql_query("Select descricao, cliente, local from terminal_cartao");
$jsonObj= array();
if($something == 'all')
{
while($result=mysql_fetch_object($sqlcode2))
{
$jsonObj[] = $result;
}
}
else{
while($result=mysql_fetch_object($sqlcode))
{
$jsonObj[] = $result;
}
}
foreach ($jsonObj as $key => $value) {
if ($value === null) {
$jsonObj[$key] = "";
}
}
$final_res =json_encode($jsonObj);
echo $final_res;
exit;