i have this PHP code, and a DataBase with “Question”, “answer1”, “answer2”, “Question_id” well, when i make an SQL Query from PHP and encode the answer to send an Android app, ONLY the “Question” field is null, i read that it could be the code, but my DataBase is encoded in utf-8. I also try to convert the result to utf-8 with the “utf8_encode” function in PHP but it doesn’t work, so i ask for some help 😛
Here’s the code (i deleted the code to conect to de DataBase and some un-used lines….)
$sql=mysql_query("SELECT * FROM Questions");
$num_rows = mysql_num_rows($sql);
$max_value = (int)$num_rows;
$quest_id = rand ( 1, $max_value);
$sql=mysql_query("SELECT * FROM Questions WHERE id_quest = $quest_id");
$row = mysql_fetch_array($sql);
$output[]=$row;
echo(json_encode($output));
mysql_close();
Thank you very much 😀
I think you are slightly mistaken. Your database might be encoded in UTF8, but the communication from php to and from the database isn’t (it’s latin1 / ISO-8859-1 by default).
Unless you are doing a
somewhere that you didn’t share with us, that is the solution you should be looking into.