title: How create Json by PHP
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2467945/how-to-generate-json-file-with-php">How to generate .json file with PHP?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to use php to create a json like below. it will  return a string json as a response from result sql query. How do I do?</p>
  
  <pre><code>{"Orders":[  
              {"DeliveryId":"DeliveryId","CustomerName":"CustomerName","PhoneNumber":"PhoneNumber","Address":"Address"},  
              {"DeliveryId":"DeliveryId","CustomerName":"CustomerName","PhoneNumber":"PhoneNumber","Address":"Address"}               
  ]
  }
  </code></pre>
  
  <p>my code</p>
  
  <pre><code>&lt;?php
  mysql_connect("mysql12.000webhost.com","a4602996_longvan","longvan2012");
  mysql_select_db("a4602996_lv"); 
  $id=$_POST[user];
  $sql=mysql_query("select * from testlongvan where Status = 'PACKED'" ); 
  
  $json = array();
  if(mysql_num_rows($sql)){
  while($row=mysql_fetch_row($sql)){
  $json['Orders'][]=$row;
  }
  }
  
  //while($row=mysql_fetch_assoc($sql))
  //$output[]=$row;
  print(json_encode($json)); 
  mysql_close(); 
  ?&gt;
  </code></pre>
  
  <p>But when use my code i recieve result, don't result i want:</p>
  
  <blockquote>
    <p>{"Orders":[
    ["longvan","10/12/2012","Be34433jh","Long Van","115 Pham Viet Chanh, quan Binh Thanh","http://longvansolution.tk/image/sample.jpg","PACKED","0909056788"],
        ["takeshi","24/12/2012","BF6464633","Vn-zoom","16 nguyen cuu van, quan binh thanh","http://longvansolution.tk/image/hoadon3.jpg","PACKED","098897657"]
        ]}
    Can you help me! </p>
  </blockquote>