I am using PHP/MySQL to run a query and encode it as JSON, but I'm unsure how to get the JSON into the form that I need.
Here is my PHP:
$myquery1 = "select 'links' as type, source, target, value from table";
$myquery2 = "select 'nodes' as type, name from table2";
$query = mysql_query($myquery1);
if ( ! $query ) {
echo mysql_error();
die;
}
$data = array();
for ($x = 0; $x < mysql_num_rows($query); $x++) {
$data[] = mysql_fetch_assoc($query);
}
//(and again for myquery2)
echo json_encode($data); //not sure how to combine queries here
I would like the JSON to be grouped grouped by "type," like this:
{
"links": [{"source":"58","target":"john","value":"95"},
{"source":"60","target":"mark","value":"80"}],
"nodes":
[{"name":"john"}, {"name":"mark"}, {"name":"rose"}]
}
Any help is much appreciated. Thank you!