PHP is not returning the query data

0

Hello,

I'm using the following code to return the regions:

$query = 'SELECT * FROM Regiao';
    $json = array();
    $result = mysqli_query ($conn, $query);
    while($row = mysqli_fetch_array ($result))
    {
        $regiao = array(
            'id' => $row['Id'],
            'nome' => $row['Nome'],
        );
        array_push($json, $regiao);
    }

    $jsonstring = json_encode($json);
    echo $jsonstring;

    die();

The result is as follows:

[
    {
        "id": "1",
        "nome": "Norte"
    },
    {
        "id": "2",
        "nome": "Nordeste"
    },
    {
        "id": "3",
        "nome": "Sudeste"
    },
    {
        "id": "4",
        "nome": "Sul"
    },
    {
        "id": "5",
        "nome": "Centro-Oeste"
    }
]

I'm using the same code but in another file with the different select:

$query = 'SELECT * FROM Estado';
    $json = array();
    $result = mysqli_query ($conn, $query);
    while($row = mysqli_fetch_array ($result))
    {
        $regiao = array(
            'id' => $row['Id'],
            'codigouf' => $row['CodigoUf'],
            'nome' => $row['Nome'],
            'uf' => $row['Uf'],
            'regiao' => $row['Regiao'],
        );
        array_push($json, $regiao);
    }

    $jsonstring = json_encode($json);
    echo $jsonstring;

    die();

And the result in the second code is Blank, it does not return anything at all. Could someone help me please? Thanks

    
asked by anonymous 20.01.2018 / 15:42

1 answer

0

Probably the name column should be filled with fields with accents (eg Paraná). First, try to get the column name and see if it returns any results.

If you return try adding the following text to your wish: link

mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');
    
20.01.2018 / 17:01