Reputation: 97
This was working absolutely fine until today when it just suddenly stopped working... (I know that isn't very helpful but I've looked around everywhere)
I'm iterating through the values returned from a mySQL query and putting each of them into an array which is then placed inside another array. I then try to JSONEncode this array and echo that, but this no longer works.
$rows = array();
while(($row = mysqli_fetch_array($result))) {
$record = array("ID" => $row[0],"image" => $row[1]);
$rows[] = $record;
}
echo json_encode($rows);
This literally just returns a blank page. But a vardump of the $rows variable shows that it's populated with all of the arrays
array (size=50)
0 =>
array (size=2)
'ID' => string '13847519' (length=8)
'image' => string 'path to image' (length=13)
1 =>
array (size=2)
'ID' => string '73829485' (length=8)
'image' => string 'path to image' (length=13)
...
Any help would be greatly appreciated! I'm just so confused!
Upvotes: 2
Views: 1142
Reputation: 1181
json_encode
can return null
in case NON UTF characrers. So please run:
var_dump(json_encode($rows));
and you will see null
. You can try solution in link above.
Upvotes: 1