-3

I can't echo $arreglo on line 23, the screen is blank. I am trying json encode, but I don't know why is not working. I have checked the conexion and it is ok...

<?php

include ("conexion.php");

$query = "SELECT * FROM usuario WHERE estado = 1 ORDER BY idusuario desc;";
$resultado = mysqli_query($conexion, $query);

if (!$resultado)
{
    die("error");
} 
else
{

    while($data = mysqli_fetch_assoc($resultado))
    {
        //echo $arreglo["data"][]=array_map("utf8_encode", $data);
     $arreglo["data"][] = $data;

    }


    echo json_encode($arreglo);


    mysqli_free_result($resultado);
    mysqli_close($conexion);
}

?>
  • 1
    Are you getting any results back? Why not `var_dump` your result set first to make sure. – Chip Dean Jul 03 '17 at 22:21
  • Turn on errors and it'll tell you what is wrong. Blank screen almost always mean there's an error. – Doug Jul 03 '17 at 22:24
  • 1
    ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); – Doug Jul 03 '17 at 22:25
  • var_dump($arreglo) returns the data: array(1) { ["data"]=> array(14) { [0]=> array(5) { ["idusuario"]=> string(2) "22" ["nombre"]=> string(6) "Carlos" ["apellidos"]=> string(6) "�valos" ["dni"]=> string(8) "26859103" ["estado"]=> string(18) "650840532079083521" } [1]=> array(5) { ["idusuario"]=> string(2) "21" ["nombre"]=> string(5) "Marco" ["apellidos"]=> string(7) "Cordova" ["dni"]=> string(8) "46851298" ["estado"]=> string(18) "650840875676467201" } [2]=> array(5) { ["idusuario"]=> string(2) "20" ["nombre"]=> string(7) "Violeta" ["apellidos"]=> string(6)... – Jesus Salas Jul 04 '17 at 20:31

1 Answers1

-2

You need to use header before echo. check the code.

header('Content-type: application/json');
echo json_encode($arreglo);