2

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!

2
  • 3
    Have you checked your error log (for apache or whatever you're using)? Commented Jun 18, 2015 at 17:00
  • View page source? Sure its something that just didn't render visibly to HTML? Commented Jun 18, 2015 at 17:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.