title: Returning JSON from PHP into Array
body: <p>I want to take the returning JSON object and display what the PHP query returned, but when I use brackets to access the indices value it displays only one character at a time. Basically I want each index to contain each row from the query. This particular query has two results (the id and file name). I would like to get both the id and name into one index of the JSON array. Output displayed below:</p>
  
  <pre><code>7 5.jpg
  8 7-mini.jpg
  </code></pre>
  
  <p>Here is my code...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
    $(function(){
      $.ajax({                                      
        url: '&lt;?php echo base_url().'jqueryDB/jquery';?&gt;',   
        type:'POST',      
        dataType: 'json',    
        success: function(output_string){
                  document.write(output_string[0]);
        }
      });
  
    }); 
  </code></pre>
  
  <p>
  Right now this display '7', instead of '7 5.jpg'. How can I get it to store each row into one index?</p>
  
  <p>Here's my PHP file:</p>
  
  <pre><code>    $userID = $this-&gt;session-&gt;userdata('id');   
      $query = $this-&gt;db-&gt;query('SELECT * FROM upload WHERE userID = '.$userID);
      $num_rows = $query-&gt;num_rows();
      $val = $query-&gt;row_array();    
  
      $output_string = "";  
  
      foreach ($query-&gt;result() as $row){
          $output_string .= $row-&gt;id;
          $output_string .= " ".$row-&gt;name."&lt;br /&gt;";
      }
  
      echo json_encode($output_string);
  </code></pre>