I have a json encoded array, which can change based on how many are returned from my query in my php code:
$mysqli = new mysqli('test', 'root', '', 'test');
$mysqli->set_charset('utf8');
$array = array();
$query = $mysqli->query("SELECT * FROM test.table1 WHERE id = '$id'");
while($row = $query->fetch_assoc()) {
$array[] = $row['char'];
}
json_encode($array);
example:
array("a", "b", "c", "d"); or
array("a", "b", "c", "d", "e"); or
array("a", "b", "c", "d", "e", "f");
I was wondering how to display the array line by line
example:
a
b
c
d
$.ajax({
url: code.php,
data: {
id: id,
},
dataType: 'json',
cache: false,
success: function(d) {
$('#code').text(d);
},
error: function() {
}
});
I know the above ajax code is wrong but how can I make it right?