こんにちは、最終結果が以下のjson配列のようになる連想配列をjson_codeしようとしています
var json =[{ "adjacencies": [
{
"nodeTo": "graphnode9",
"nodeFrom": "graphnode5",
"data": {}
}
],
"data": {
"$color": "#C74243",
"$type": "triangle"
},
"id": "graphnode5",
"name": "graphnode5"
}];
これは、連想配列を json_encode に取得しようとする試みですが、うまくいかないようです。表示されるエラーはありますか? どうもありがとうございます
function getjson(){
$db = adodbConnect();
$query = "SELECT nodes.*, relationships.* FROM nodes inner JOIN relationships ON nodes.id = relationships.id";
$result = $db -> Execute($query);
while($row=$result->FetchRow())
{
$id= (float)$row['id'];
$name = $row['name'];
$color1 = $row['color'];
$type1 = $row['type'];
$to= (float)$row['to'];
$array = array(
"adjacencies:" => array(
"nodeTo" => "$to",
"nodeFrom" => "$id",
"data" => array() ),
"data" => array(
"$"."color" => $color1,
"$"."type" => $type1 ),
"id".":" => $id,
"name".":" => $name);
}
print"$array";
json_encode($array);
}