title: building json by using mysql fetch result
body: <p>hello i want to use my mysql result to build the json objects. my first query is fetching parent menu and another query is fetching child menu so i am going to put my child menu result under the parent menu.. i want to know what is wrong with my code and how to correct</p>
  
  <pre><code>&lt;?php
      $selectparentMenu=mysql_query("SELECT `id`,`item_name`,`menu_type`,`parent` FROM `epic_master_menu` where parent=0");
      //echo $myfetch=mysql_fetch_array($selectMenu);
          if(mysql_num_rows($selectparentMenu)&gt;1) {
      while($fetchparentMenu=mysql_fetch_array($selectparentMenu)) {
           //echo 'parent id is' .$parentId=$fetchparentMenu['id']. '&lt;br/&gt;';
          // echo 'parent name is' .$parentId=$fetchparentMenu['item_name']. '&lt;br/&gt;';
  
  
           $selectchildMenu=mysql_query("SELECT `id` , `item_name` , `menu_type` , `parent` FROM `epic_master_menu`
      WHERE parent &gt;0 AND `menu_type` = 'item' AND `parent` ='".$fetchparentMenu['id']."'");
      if(mysql_num_rows($selectchildMenu)&gt;1) {
           while($fetchchildMenu=mysql_fetch_array($selectchildMenu)) {
  
               $textjson = '{
      "dataSource": [{
              "id": "", "text": "Select All", "expanded": "true", "spriteCssClass": "rootfolder", "items": [
                  {
                      "id": "'.$fetchparentMenu["id"].'", "text": "'.$fetchparentMenu["item_name"].'", "expanded": true,"spriteCssClass": "folder", "items": [
                          { "id": "'.$fetchchildMenu["id"].'", "text": "'.$fetchparentMenu["item_name"].'", "spriteCssClass": "html" },
                          { "id": "'.$fetchchildMenu["id"].'", "text": "'.$fetchparentMenu["item_name"].'", "spriteCssClass": "html" },
                          { "id": "'.$fetchchildMenu["id"].'", "text": "'.$fetchparentMenu["item_name"].'", "spriteCssClass": "image" }
                      ]
                  }
              ]
          }]
      }';
  
               }  }
  
           /* $fetchMenu['item_name'];
             $fetchMenu['menu_type'];
             $fetchMenu['parent'];*/
          //print_r($fetchMenu);
          } }
  </code></pre>
  
  <p>// my json data is </p>
  
  <pre><code> $textjson = '{
  "dataSource": [{
          "id": 1, "text": "My Documents", "expanded": "true", "spriteCssClass": "rootfolder", "items": [
              {
                  "id": 2, "text": "Project", "expanded": true,"spriteCssClass": "folder", "items": [
                      { "id": 3, "text": "about.html", "spriteCssClass": "html" },
                      { "id": 4, "text": "index.html", "spriteCssClass": "html" },
                      { "id": 5, "text": "logo.png", "spriteCssClass": "image" }
                  ]
              },
              {
                  "id": 6, "text": "New Web Site", "expanded": true, "spriteCssClass": "folder", "items": [
                      { "id": 7, "text": "mockup.jpg", "spriteCssClass": "image" },
                      { "id": 8, "text": "Research.pdf", "spriteCssClass": "pdf" }
                  ]
              },
              {
                  "id": 9, "text": "Reports", "expanded": true, "spriteCssClass": "folder", "items": [
                      { "id": 10, "text": "February.pdf", "spriteCssClass": "pdf" },
                      { "id": 11, "text": "March.pdf", "spriteCssClass": "pdf" },
                      { "id": 12, "text": "April.pdf", "spriteCssClass": "pdf" }
                  ]
              }
          ]
      }]
  }';
  </code></pre>