I am trying to return the result of a mysql query as json, but the json_encode function always returns a blank although the array contains elements.
Here is the relevant code
Retrieve the query and convert to php array:
$sql = "blablabla";
$clients = mysql_query($sql, $con);
$result = array();
while($row = mysql_fetch_assoc($clients)) {
//echo "rij: " . $row['name'];
$result[] = $row;
}
Then I return the result:
echo json_encode($result);
This returns nothing, while I do get results when echoing the following statements:
echo count($return);
returns 1
echo $return[0];
returns "Array"
echo $return[0]['name'];
returns "YOUREKA! demo"
Any idea what I am doing wrong?
Edit: I have one record that is and should be returned which contains following data:
id: 2, name: YOUREKA! demo, address: Italiëlei 26, postalcode: 2000, city: Antwerpen, country: België, countrycode: BE, telephone: +32-476061346, email: [email protected], distance: 30.762980999827132,
falseon error. What does json_last_error_msg say?$result[] = $row['name'];