0
hello
I have a problem I believe you can help me, is the following need to have a json of this genus
{
"nodes":[
{"name":"Barry"},
{"name":"Frodo"},
{"name":"Elvis"},
{"name":"Sarah"},
{"name":"Alice"}
],
"links":[
{"source":"Barry","target":"Elvis","value":2},
{"source":"Frodo","target":"Elvis","value":2},
{"source":"Frodo","target":"Sarah","value":2},
{"source":"Barry","target":"Alice","value":2},
{"source":"Elvis","target":"Sarah","value":2},
{"source":"Elvis","target":"Alice","value":2},
{"source":"Sarah","target":"Alice","value":4}
]}
I’m generating in this way
$stmt->execute();
$nodes = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmptrabalho->execute();
$links = $stmptrabalho->fetchAll(PDO::FETCH_ASSOC);
$array = array(
'nodes' => $nodes,
'links' => $links
);
$fp = fopen('json.json', 'w');
fwrite($fp, json_encode($array,JSON_UNESCAPED_UNICODE));
fclose($fp);
generates me the file only it is all on the same line there is some way to save as the file above another thing happens to me is the value appear with "in value and should not"
new result
"nodes": [
{
"name": "Alentejo Central"
},
{
"name": "Alentejo Litoral"
},
{
"name": "Algarve"
},
{
"name": "Alto Alentejo"
},
{
"name": "Alto Trás-os-Montes"
},
{
"name": "Ave"
},
{
"name": "Baixo Alentejo"
},
{
"name": "Baixo Mondego"
},
{
"name": "Baixo Vouga"
},
{
"name": "Beira Interior Norte"
},
{
"name": "Beira Interior Sul"
},
{
"name": "Cávado"
},
{
"name": "Cova da Beira"
},
{
"name": "Dão-Lafões"
},
{
"name": "Douro"
},
{
"name": "Entre Douro e Vouga"
},
{
"name": "Estrangeiro"
},
{
"name": "Grande Lisboa"
},
{
"name": "Grande Porto"
},
{
"name": "Lezíria do Tejo"
},
{
"name": "Médio Tejo"
},
{
"name": "Minho-Lima"
},
{
"name": "nao se aplica"
},
{
"name": "Não se aplica"
},
{
"name": "Oeste"
},
{
"name": "Península de Setúbal"
},
{
"name": "Pinhal Interior Norte"
},
{
"name": "Pinhal Interior Sul"
},
{
"name": "Pinhal Litoral"
},
{
"name": "Região Autónoma da Madeira"
},
{
"name": "Região Autónoma dos Açores"
},
{
"name": "Serra da Estrela"
},
{
"name": "Tâmega"
}
],
"links": [
{
"source": "Alentejo Central",
"target": "Alentejo Central",
"value": "3939"
},
{
"source": "Alentejo Central",
"target": "Alentejo Litoral",
"value": "47"
},
{
"source": "Alentejo Central",
"target": "Algarve",
"value": "113"
},
this photo is what I have in the postgres concerning the data I want to show in sankety
{ "source": "T u00e2mega", "target": "Regi u00e3o Aut u00f3noma dos A u00e7ores", "value": "28" }, { "source": "T u00e2mega", "target": "Star Saw", "value": "4" }, { "source": "T u00e2mega", "target": "T u00e2mega", "value": "12920"
"; }
– usersantos
gets the middle part separated and desecrated fields
– usersantos
I tested now, I show the result the above
– Miguel
I’ll go through with it
– usersantos
what may be happening in my case will be that I have read well done php I think so
– usersantos
Exactly, like mine. If you want a more customised json output I don’t think I can help you.
– Miguel
May I ask why this need?
– Miguel
I have a paper on D3.js that is the necessity
– usersantos
I don’t know. It doesn’t work this way?
– Miguel
no. friend tried to put up less data and nothing
– usersantos
convert this query to Pdo $nodes = array(); for ($x = 0; $x < mysql_num_rows($query); $x++) { $nodes[] = mysql_fetch_assoc($query); }
– usersantos
How are you holding up the result of json.json? That’s how it is:
d3.json("json.json", function(data) {...
?– Miguel
yes it is but I saw that I can call php directly .
– usersantos
Yes you can, just do the
echo
json– Miguel
yes that’s what I did and works with the example now with my data is that no and I do not know why..
– usersantos