1

I have a mysqli table on a server with the configuration displayed below. The text data contains some special characters. I'm passing this to my android app using the following php file. The issue is that all the special characters are displayed as question marks in the app. I'm not sure if I need to specify that we're passing unicode characters in the php file and if so how to do that. It's not a font issue, as any special characters hardcoded into the app display as expected.

<?php


// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connectmaths.php';

// connecting to db
$con = new DB_CONNECT();
$con->connect();

// get all gamelists from gamelists table
$result = mysqli_query($con->myconn, "SELECT * FROM `abcd`" ) or die(mysql_error());


// check for empty result
if (mysqli_num_rows($result) > 0) {
    // looping through all results
    // gamelists node
    $response["gamelist"] = array();
    
    while ($row = mysqli_fetch_array($result)) {
        // temp user array
        $gamelist = array();
        $gamelist["id"] = $row["id"];
        $gamelist["zadanie"] = $row["zadanie"];
        $gamelist["odp_a"] = $row["odp_a"];
        $gamelist["odp_b"] = $row["odp_b"];
        $gamelist["odp_c"] = $row["odp_c"];
        $gamelist["odp_d"] = $row["odp_d"];
        $gamelist["comment"] = $row["comment"];
        $gamelist["correctanswer"] = $row["correctanswer"];
        



        // push single gamelist into final response array
        array_push($response["gamelist"], $gamelist);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no gamelists found
    $response["success"] = 0;
    $response["message"] = "No gamelists found";

    // echo no users JSON
    echo json_encode($response);
}
?>

enter image description here

1 Answer 1

0

What's Charset yours Datas ? When my Datas have e.g. charset cp1250 i have to transfer Strings to utf8. Change PHP script

...
while ($row = mysqli_fetch_array($result)) {
    // temp user array
    $gamelist = array();
    $gamelist["id"] = $row["id"];
    //$gamelist["zadanie"] = $row["zadanie"];
    $gamelist["zadanie"] = iconv("CP1250", "UTF-8", $row["zadanie"]);
    $gamelist["odp_a"] = $row["odp_a"];
    $gamelist["odp_b"] = $row["odp_b"];
    $gamelist["odp_c"] = $row["odp_c"];
    $gamelist["odp_d"] = $row["odp_d"];
    $gamelist["comment"] = $row["comment"];
    $gamelist["correctanswer"] = $row["correctanswer"];




    // push single gamelist into final response array
    array_push($response["gamelist"], $gamelist);
}
...

The same before i save Datas from App to Mysql i have to transfer

...
$zadanie = iconv("UTF-8", "CP1250", $_POST['zadanie']);
...
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.