title: JSON encode for multiple MySQL rows
body: <p>I'm working on outputting multiple MySQL JSON rows to an HTML table via PHP (server side) and jQuery (front end) through a simple search box. I've successfully managed to parse one row of JSON to the table but now need to accommodate multiple rows of JSON data.</p>
  
  <p>My HTML table on the search page looks something like this:</p>
  
  <pre><code>ARTIST | TITLE | LOCATION 
  U2     | One   | Ireland 
  Foals  | Miami | UK
  </code></pre>
  
  <p>and the JSON file passed to it utilises similar headings:</p>
  
  <pre><code>{"ARTIST":"Katy Perry","LOCATION":"United States", "TRACKTITLE":"Roar"}
  </code></pre>
  
  <p>I've been playing around with the code for a while, incorporating arrays to loop through the data. This works in as much as it loops through the MySQL rows correctly and successfully sends multiple rows of data back in JSON format (I've decoded my search page in Firebug). The problem is that my jQuery file can't place it into my HTML table, resulting in a blank page. I've tried various methods of arrays from previous Stackoverflow questions but can't quite get it to work, being returned the 'ARTIST', 'TRACKTITLE' and 'LOCATION' fields with every returned result</p>
  
  <p><strong>extract from PHP file:</strong></p>
  
  <pre><code>$result = mysql_query($sql);
  $data = array();
  while ($array = mysql_fetch_assoc($result)) {
  $data[] = $array;
  }
  echo json_encode($data);
  </code></pre>
  
  <p><strong>Edited to include jQuery extract and more specific question</strong>:</p>
  
  <pre><code>function(data) {
  var sentData=JSON.parse(data)
  for (var i = 0; i &lt; sentData.ARTIST.length; ++i)
  {
  tr = $('&lt;tr/&gt;');
  tr.append("&lt;td&gt;" + sentData.ARTIST + "&lt;/td&gt;");
  tr.append("&lt;td&gt;" + sentData.TRACKTITLE + "&lt;/td&gt;");
  tr.append("&lt;td&gt;" + sentData.LOCATION + "&lt;/td&gt;");
  $('#multiple').append(tr);
  }
  });
  </code></pre>
  
  <p>How can I parse only the corresponding values of each 'ARTIST', TRACKTITLE' and 'LOCATION' result using the JSON.parse method? This is the full returned JSON string:</p>
  
  <pre><code>[{"ARTIST":"Katy Perry","TRACKTITLE":"Roar","LOCATION":"United States"}, {"ARTIST":"U2","TRACKTITLE":"One","LOCATION":"Ireland"}]
  </code></pre>