0

Ok, hang on with me. I am really bad at this. I have received little help from friend who knows some coding but is not available atm.

I have mysql database which contains data stored in UTF8_general_ci

Then in wordpress I have page which calls file number 1, haku.php. Contents below:

 <?php

$result = mysql_query("SELECT DISTINCT jalleenmyyja_postitp FROM jalleenmyyjat order by jalleenmyyja_postitp");
while($r = mysql_fetch_array($result)){
if ($r["jalleenmyyja_postitp"] != "")echo '<option  value="'.$r["jalleenmyyja_postitp"] .'">'. $r["jalleenmyyja_postitp"] .'</option>';
}


?>

Those are then put inside dropdown menu. So far so good. Then when some selection is done in dropdown, it should return results below which it does by file number 2 which is JS below:

    function haeyritys(x){
jQuery.ajax({
  type: "POST",
  url: "/yrityshaku.php",
  data: "kaupunki=" + x,
  success: function(data){
    document.getElementById('selResult').innerHTML=data;
  }

});
}

Then after this the file number 3. returns the data from database.

if($_REQUEST["kaupunki"] !=""){

    $con = mysql_connect($host, $user, $pass);

    mysql_select_db($db_name);

    $result = mysql_query("select * from jalleenmyyjat where jalleenmyyja_postitp = '" .  utf8_decode($_REQUEST["kaupunki"]) ."' order by jalleenmyyja_nimi");



    if (mysql_num_rows($result) == 0){

            echo '<div style="border-bottom:1px solid #ccc;padding:5px;"><b>Ei tuloksia...</b>';

    }else{

        while($r = mysql_fetch_array($result)){

            if ($r["google"] != ""){echo '<a onclick="location.href=\'#top\'" href="'. $r["google"] .'" target="map">';}else{echo '<a onclick="location.href=\'#top\'" href="/eikarttaa.html" target="map">';}

            echo '<div style="border-bottom:1px solid #ccc;padding:5px;"><b>' . $r["jalleenmyyja_nimi"] . '</b>';

            if ($r["jalleenmyyja_osoite"] != "")echo '<br>' . $r["jalleenmyyja_osoite"]; 

            if ($r["jalleenmyyja_postino"] !="" ||  $r["jalleenmyyja_postitp"] !="")echo "<br/>" . $r["jalleenmyyja_postino"] . " ".  $r["jalleenmyyja_postitp"];

            if ($r["jalleenmyyja_puh"] != "") echo "<br/>Puh: ". $r["jalleenmyyja_puh"];

            if ($r["www"] != "")echo '<br/><a  target="_blank" href="'.$r["www"].'">Verkkosivuille &raquo;</a>';

            echo '</div>';

            echo '</a>';


        }   

    }



    mysql_close($con);



}

?>

However, the foreign characters are question marks. If I add mysql_set_charset('utf8'); to file number 3 which opens the database connection, the results show symbols correctly but the data in dropdown which could have the symbol, does not return results! so it's one way or the other.

mavili
  • 3,385
  • 4
  • 30
  • 46
  • 1
    Have a read of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Anigel Aug 22 '13 at 13:14

1 Answers1

0

If you see question marks in place of characters on a web page, chances are the browser does not know which charset is the correct one. You can tell the browser which charset to use by one of the following methods:

HTML5:

<meta charset="UTF-8">

HTML4:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

XHTML 1.x:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

XHTML 1.x as XML:

<?xml version="1.0" encoding="UTF-8"?>

The meta tags belong in the head of the html document, and should be placed near the top (between <head> and </head>). If unsure about which one to use, use html4 for supporting old browsers, html5 if support for modern browsers is sufficient.

Source

Jo Are By
  • 3,293
  • 1
  • 11
  • 11