Scenario: I have a query made in PHP and I need to return it to my iOS app in JSON format. However when doing some tests, in the browser, I noticed that using the echo json_enconde($resultado);
function returns less results on the screen. For example, my database has about 200 records in a column, but using json_encode
, only some column values appear, and when I use only echo
, returns all results.
Does anyone know why there is such a reduction in values using json_encode
?
Below is my code in PHP:
include "conexao.php";
// Pucha o conteudo do processo que fica na coluna todo_resto
$sql = "select todo_resto from registros";
$resultado = mysql_query($sql) or die ("Erro .:" . mysql_error());
// Criando variável linha do tipo array
$linha = array();
while($r = mysql_fetch_object($resultado))
{
$linha [] = $r->todo_resto;
}
// Não funciona
// echo json_encode($linha);
// Não funciona
// print_r(json_encode($linha));
mysql_close();
?>
After some tests I made a change in the while
of the code, thus:
while($r = mysql_fetch_object($resultado))
{
echo ($r->todo_resto)."######";
}
I can print all the values, but when I enter the json_encode
, it only returns some values of the bank, the rest are blank (null).
while($r = mysql_fetch_object($resultado))
{
echo json_encode($r->todo_resto)."#";
}