2
I am working in a personal project with an open database, and I need a JSON file from a MYSQL query, I am a few days trying to solve this problem and I am very difficult, because I can not get the name of my data. Example: I make a query to list all states, I can get json with the ID, UF, Region, when I put the name field, returns me nothing and gives the error Resource Interpreted as Document but transferred with MIME type application/json: "http://localhost/teste.php". My goal is to take all the query data and return a JSON to deal with Geocharts.
<?php
$con = mysqli_connect("localhost","root","3919223","DatasusNew") or die("Error " . mysqli_error($con));
mysqli_query('SET NAMES utf8;');
$var = array();
$sql = "SELECT * FROM estados";
$result = mysqli_query($con, $sql);
foreach ($result as $row) {
$return[] = [
'nome' => $row['nome'],
'idEstado' => $row['idEstado'],
'uf' => $row['uf'],
'regiao' => $row['regiao']
];
}
$dbh = null;
header('Content-type: application/json');
echo json_encode($return);
?>
Has anyone been through this problem? Or any tips?
friend, just out of curiosity: I saw that your bank is called datasusnew. I also develop for Datasus systems. get in touch with me so we can exchange an idea. hug
– Italo Rodrigo