0

My table which I am getting my data from is in "Latin_1" however when the data is returned the fields with German characters in get returned as empty. Why is it doing this ? does json encode affect the char set? other than that I am completely lost.

I have read you can set the character set in php but it is already set correctly and the table has the special characters in ?

Edit//

here is the code i am using __php:

function getInfo($country){

    $rows = array();
    $query = "SELECT name,add1,add2,town,district,postcode FROM stockistsWorld WHERE country = '". mysql_escape_string($country) ."' LIMIT 4 ";
    //$query = "SELECT Name,add1 FROM stockistsUK LIMIT 10";
    $result = mysqli_query($this->conn, $query);
    /* numeric array */

    while($row = mysqli_fetch_array($result, MYSQLI_NUM)){

         $rows[] = $row;

        }

    return $rows;
}

and this is the ajax request__

function ajaxData(country){
//get data from database return into inf array 
var infArray = new Array();
 $.ajax({
        type: 'POST',
        url: 'php/Maps.php',
        data: {country: country},
        success: function(data){
        infArray = JSON.parse(data);
        geoCodeClientSide(infArray);
        }           
    });

}

  • Why are you using `mysql_escape_string` when you are working with `mysql**i**` – PeeHaa Aug 03 '13 at 18:41
  • This is my first time, i just thought that you had to do that to stop sql injection –  Aug 03 '13 at 18:41
  • http://php.net/manual/en/mysqli.real-escape-string.php – PeeHaa Aug 03 '13 at 18:49
  • Thankyou peehaa, but do you have any idea on the encoding ? I can't find out anything more on it –  Aug 03 '13 at 18:51
  • http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – PeeHaa Aug 03 '13 at 18:52
  • I have set every possible encoding in the database, html, tables, mysqli connection to utf-8 but it still is not working –  Aug 03 '13 at 18:58

1 Answers1

0

Please set the charset for your db/table as utf-8.

Thanks, Neo

Pranay Bhardwaj
  • 1,059
  • 8
  • 9
  • I have changed it to this but it still is not returning the umlauts ? i thought utf 8 didn't support this? –  Aug 03 '13 at 18:45
  • please check the specific data in table manually, are you able to read those characters? If not then you need to insert the data again after changing the charset to utf-8 – Pranay Bhardwaj Aug 03 '13 at 19:19
  • in my sql if i query the database the special characters turn up –  Aug 03 '13 at 19:22
  • Okay, can you print the 'data' before coverting it to JSON and check if its coming fine? – Pranay Bhardwaj Aug 03 '13 at 19:25
  • I think your html/php is unable to render chrset as utf-8. – Pranay Bhardwaj Aug 03 '13 at 19:28
  • so i took it back to just echoing straight from the database call umlauts come as � however when not converting to json the rest of the field is returned #sobloodyconfused –  Aug 03 '13 at 19:47
  • so i tested it with a new table and it worked so by that logic it must be a problem with the table –  Aug 04 '13 at 12:46