试图将MySQL数据放入d3的嵌套json文件中

试图将MySQL数据放入d3的嵌套json文件中

本文介绍了试图将MySQL数据放入d3的嵌套json文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MySQL数据库数据转换为json格式.我的文件必须采用嵌套父母和孩子的格式. (请参阅摘要)这是因为我试图使用d3数据可视化(可折叠的树形布局),该可视化要求以某种方式格式化json数据.下面我附上了我的json文件的摘要.我在尝试编写嵌套的sql语句来执行此操作时遇到了一些问题.我还附加了数据库的视觉效果,以查看正在处理的内容.任何建议都会有很大帮助.谢谢!

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!

我要获取的json格式如下:

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":"[email protected]"},
                        {"name":"dan", "email":"[email protected]"}
                        ]
                    },
                    {
                    "name": "project2",
                    "description":"project 2 text goes here",
                                "children":[
                        {"name":"steve", "email":"[email protected]"},
                        {"name":"chris", "email":"[email protected]"}
                                ]
                    }
                    ]
            },
            {
            "name": "sub_category_name2",
            "description":"sub category description text goes here..",
            "children": [
                {"name": "project3",
                "description":"project3 text goes here ",
                "children":[
                    {"name":"Alex", "email":"[email protected]"}
                ]
                }
            ]
            }

    ]
    },
    .
    . //more categories with children of subcategories and sub_cat children of projects
    .
}

推荐答案

我过去在本教程中取得了成功: http://www.d3noob.org /2013/02/using-mysql-database-as-source-of-data.html

I've had success with this tutorial in the past:http://www.d3noob.org/2013/02/using-mysql-database-as-source-of-data.html

简而言之,您将要做的是创建一个连接到MySql的php文件,执行查询并将结果转换为json.然后,您将使用此文件代替d3代码中的数据源.

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.

这篇关于试图将MySQL数据放入d3的嵌套json文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 14:04