title: PHP build a specific JSON string from postgresql Database
body: <p>I want use zachhunters json to html tabel script with my postressql db so i need a specific JSON string format but i dont know how to build it ... (i am new in json)</p>
  
  <p><a href="http://www.zachhunter.com/2010/04/json-objects-to-html-table" rel="nofollow">Link to the Script</a></p>
  
  <p>I get my data using</p>
  
  <pre><code>$result = pg_fetch_array($rs, NULL, PGSQL_ASSOC);
  </code></pre>
  
  <p>When i use <code>json_encode($result)</code> i get this:</p>
  
  <pre><code>{"id":"2","surname":"Max","name":"Muster"} etc.
  </code></pre>
  
  <p>For the Script i need somthing like:</p>
  
  <pre><code>{ "d": "[{\"id\":1,\"Username\":\"Sam Smith\"},{\"id\":2,\"UserName\":\"Fred Frankly\"}]" }
  </code></pre>
  
  <p>How can i handle this?</p>