I have a database with 5 columns and multiple rows. I'm using PHP to fetch the data and echo it as JSON as an array. The way it echoes it is the data in each row is an array and the rows themselves are an array (array within an array).
Now I bring the data in using Ajax and want to split the array within an array. I can only split down the rows so far. How would I split further?
Here's the PHP:
//==== FETCH DATA
$result = mysql_query("SELECT * FROM $tableName");
//==== PUT DATA INTO ARRAY
$array = array();
while ($row = mysql_fetch_row($result)) {
$array[] = $row;
}
//==== ECHO AS JSON
echo json_encode($array);
Here's the Ajax:
$.ajax({
url: 'assets/php/results.php',
data: "",
dataType: 'json',
success: function(data){
//==== FETCH DATA FIELDS
var row1 = data[0];
var row2 = data[1];
//==== UPDATE HTML WITH DATA
$('#r-col span.row1').html(row1);
$('#r-col span.row2').html(row2);
}
});