title: json array for one to many relations
body: <p>I want to create a json string from two table's queries in one to many relations. I have done like this </p>
  
  <pre><code>$query = "SELECT id,name FROM sample1 ORDER BY id ASC" ;                
  $result = mysql_query($query) or die(mysql_error());
  $parent = array() ;
  
  while($row = mysql_fetch_array($result))
  {   
      $parent[]= array("id"=&gt;$row['id'],"name"=&gt;$row['name']);
      $query1 = "SELECT id,cid,cmessage FROM sample2 WHERE id = '$row[id]' ORDER BY cid ASC" ;            
      $result1 = mysql_query($query1) or die(mysql_error());
  
      while($row1 = mysql_fetch_array($result1))
      {
          $parent[] = array("id"=&gt;$row1['id'],"cid"=&gt;$row1['cid'],"comment"=&gt;$row1['cmessage']);
  
      }  
  } echo  json_encode($parent); 
  </code></pre>
  
  <p>it shows an output like this <code>[{"id":"1","name":"Arathy"},{"id":"1","cid":"11","comment":"hai"},{"id":"1","cid":"111","comment":"exe"},{"id":"2","name":"Dhanya"},{"id":"2","cid":"22","comment":"yes"}]</code></p>
  
  <p>But I want the format like as shown below ,</p>
  
  <pre><code>[
  {
      "id": "1",
      "name": "Arathy",
      "details": [
          {
              "id": "1",
              "cid": "11",
              "comment": "hai"
          },
          {
              "id": "11",
              "cid": "111",
              "comment": "exe"
          }
      ]
  },
  {
      "id": "2",
      "name": "Dhanya",
      "details": [
          {
              "id": "2",
              "cid": "22",
              "comment": "yes"
          }
      ]
  } ]
  </code></pre>
  
  <p>Please help to correct</p>