I am using Android to create a app. Where user answer are store on mySQL on server via PHP code.
function fetch_all_complaints_by_packet($packet) {
global $dBConnection;
$query = "SELECT * FROM ".DB_PREFIX ."complaint ORDER BY id DESC LIMIT 0 , 10";
$result = mysql_query($query,$dBConnection) or die('Errant query: '.$query);
$complaints = array();
if(mysql_num_rows($result)) {
$i = 0;
while($complaint = mysql_fetch_assoc($result)) {
$complaints[$i] = $complaint;
echo ($complaint['details'].'<br>');
$i++;
}
}
//echo json_encode($complaints);
}
The following line
echo json_encode();
Cause error it show details as NULL, but
echo json_encode($complaint['details'].'<br>');
Print the correct data. What the problem is?
I’ve had something similar to this maybe check on your side if the problem is the same:
When you have an invalid UTF-8 string (invalid utf-8 characters) and try to JSON_Encode that data, it will return NULL.
It took me hours to find that in my code because after all it is AJAX call so you can’t really see the errors coming out.
My suggestion is to turn error logging on and display all errors, you will probably see an error about UTF-8 encoding that failed. If not, try to utf8_decode your data and see if it shoots out the error i told you about.