I am trying to get MySQL database data into json format. My file needs to be in the format of nested parents and children. (see snippet) This is because I am trying to use a d3 data visualization (collapsible tree layout) that requires that the json data be formatted in a certain way. Below I have attached a snippet of what I the json file to look like. I am having some issues trying to write nested sql statements to do this. I have also attached a visual of my database to see what I am dealing with. Any advice will help greatly. Thanks!
The json format I am trying to get is something like this:
{
"name": "Projects",
"children": [
{
"name":"category_name#1", "description":"category",
"children": [
{
"name":"sub_category_name1",
"description":"category description text here",
"children":[
{"name": "project1",
"description":"project 1 text goes here",
"children":[
{"name":"mike", "email":"xxx@mail.com"},
{"name":"dan", "email":"xxx@gmail.com"}
]
},
{
"name": "project2",
"description":"project 2 text goes here",
"children":[
{"name":"steve", "email":"xxx@mail.com"},
{"name":"chris", "email":"xxx@gmail.com"}
]
}
]
},
{
"name": "sub_category_name2",
"description":"sub category description text goes here..",
"children": [
{"name": "project3",
"description":"project3 text goes here ",
"children":[
{"name":"Alex", "email":"xxx@gmail.com"}
]
}
]
}
]
},
.
. //more categories with children of subcategories and sub_cat children of projects
.
}
I've had success with this tutorial in the past: http://www.d3noob.org/2013/02/using-mysql-database-as-source-of-data.html
In short what you'll do is create a php file that connects to MySql, performs a query and translates the results into json. You'll then use this file in place of the data source in your d3 code.