title: about the json format (jstree, php)
body: <p>I am trying to make the data format like below. for using jstree module</p>
  
  <pre><code>[{
      "id":"1" ,
      "parent_id":"0",
      "text":"TEST",
      "children":[{
          "id":"2",
          "parent_id":"1",
          "text":"TEST1",
          "children":[{
              "id":"4",
              "parent_id":"2",
              "text":"TEST1-1"
          }, {
              "id":"5",
              "parent_id":"2",
              "text":"TEST1-2"        
          }, {
              "id":"6",
              "parent_id":"2",
              "text":"TEST1-3"        
          }]
      },  {
          "id":"3",
          "parent_id":"1",
          "text":"TEST2",
          "children":[{
              "id":"7",
              "parent_id":"3",
              "text":"TEST2-1"
          }, {
              "id":"8",
              "parent_id":"3",
              "text":"TEST2-1"
          }, {
              "id":"9",
              "parent_id":"3",
              "text":"TEST2-1"
          }]
      }]
  }]
  </code></pre>
  
  <p>but.. mine is</p>
  
  <pre><code>[{
      "id":"1" ,
      "parent_id":"0",
      "text":"TEST",
      "children":{
          "id":"3",
          "parent_id":"1",
          "text":"\ud14c\uc2a4\ud2b82",
          "children":{
              "id":"9",
              "parent_id":"3",
              "text":"\ud14c\uc2a4\ud2b82-3"
          }
      }
  },{
      "children":{
          "id":"1",
          "parent_id":"0",
          "text":"TEST1",
          "children":{
              "id":"3",
              "parent_id":"1",
              "text":"TEST2",
              "children":{
                  "id":"9",
                  "parent_id":"3",
                  "text":"TEST2-3"
              }
          }
      }
  },{
      "id":"2",
      "parent_id":"1",
      "text":"TEST1",
      "children":{
          "id":"6",
          "parent_id":"2",
          "text":"TEST1-3"
      }
  },{
      "id":"3",
      "parent_id":"1",
      "text":"TEST2",
      "children":{
          "id":"9",
          "parent_id":"3",
          "text":"TEST2-3"
      }
  },{
      "id":"4",
      "parent_id":"2",
      "text":"TEST1-1"
  },{
      "id":"5",
      "parent_id":"2",
      "text":"TEST1-2"
  },{
      "id":"6",
      "parent_id":"2",
      "text":"TEST1-3"
  },{
      "id":"7",
      "parent_id":"3",
      "text":"TEST2-1"
  },{
      "id":"8",
      "parent_id":"3",
      "text":"TEST2-2"
  },{
      "id":"9",
      "parent_id":"3",
      "text":"TEST2-3"
  }]
  </code></pre>
  
  <p>I have no idea about the arrays or JSON. Here is the code:</p>
  
  <pre><code>$refs = array();
  $list = array();
  
  $sql = "
  select id, parent_id, text
  from code
  where use_yn = 'Y'
  $result = mysql_query($sql);
  while($data = mysql_fetch_assoc($result)) {
      $thisref = &amp;$refs[$data['id']];
      $thisref['id'] = $data['id'];
      $thisref['parent_id'] = $data['parent_id'];
      $thisref['text'] = iconv("euc-kr", "utf-8", $data['text']);
  
      if ($data['id'] == 0) {
          $list[ $data['id'] ] = &amp;$thisref;
      } else {
          $refs[ $data['parent_id'] ]['children'] = &amp;$thisref;
      }
  }
  
  echo json_encode(array_values($refs));
  </code></pre>
  
  <p>Can anyone help me?</p>