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:
7 5.jpg
8 7-mini.jpg
Here is my code...
<script type="text/javascript">
$(function(){
$.ajax({
url: '<?php echo base_url().'jqueryDB/jquery';?>',
type:'POST',
dataType: 'json',
success: function(output_string){
document.write(output_string[0]);
}
});
});
Right now this display '7', instead of '7 5.jpg'. How can I get it to store each row into one index?
Here's my PHP file:
$userID = $this->session->userdata('id');
$query = $this->db->query('SELECT * FROM upload WHERE userID = '.$userID);
$num_rows = $query->num_rows();
$val = $query->row_array();
$output_string = "";
foreach ($query->result() as $row){
$output_string .= $row->id;
$output_string .= " ".$row->name."<br />";
}
echo json_encode($output_string);
var obj = jQuery.parseJSON(your_var);