Link to home
Start Free TrialLog in
Avatar of tombombadilll
tombombadilll

asked on

Swedish special characters (å,ä,ö) doesn't show in combobox when loaded from database?

Hi

I populate a combobox in Flash with names from a mySQL database.
When I do this the swedish special characters appear like black lined rects instead of their correct appearance.
The characters are (å, ä, ö) and eg. å is in html encoded like this
å

If I type in eg. åt as the label and 1 as the data then its shown correct but when its populated from a database with PHP/mySQL something seems to go wrong.
How do I solve this problem?

//Tom
Avatar of suqui
suqui

The problem is caused when you use dynamic fields and read the data from an external source like a mysql database or a text file. Special characters, like accented characters in Spanish do not display correctly unless you tell flash to use your systems codepage. To fix this, add this line somewhere before reading the external data:

system.useCodepage = true;

It should work fine.

Peter

P.S. I lived in Solna, outside Stockholm, for several years when I was small, where I learned "at prata svenska" (but not to write it properly!!!) - great country!
Avatar of tombombadilll

ASKER

Hi again...

I tried that but it didn't work. Here is the code.
The combobox is named lbx_anstalld.
My Flash is a 1 frame movie with just a combobox in it at the moment and the code below.

(Cool that you have lived in Sweden. I live like 2 hours way from Stockholm.)
---------------------------------------
system.useCodepage = true;

var lvAnstalld = new LoadVars();

lbx_anstalld.onEnterFrame = function () {
      // declare variables
      var i;
      status = "Start";
      //trace("Start");
      // function
      lvAnstalld.onLoad = function(success){
            status = "Loaded N="+this.n;
            // Do when loaded
            for (i=0; i<this.n; i++) {
                  trace("i="+i);
                  sLabel = this["a_enamn"+i] + ", " + this["a_fnamn"+i];
                  lbx_anstalld.addItem(sLabel,this["a_anstnr"+i]);
            }
      }
      
      // lbx_anstalld.removeAll();
      // Select table
      lvAnstalld.tableName = "anstalld";
      lvAnstalld.whereCondition = "";
      status = "Before Send and Load";
      //
      lvAnstalld.sendAndLoad("getTableData.php", lvAnstalld, "POST");
      status = "After Send and Load";
}

// style
lbx_anstalld.setStyle("fontFamily", "Verdana");
lbx_anstalld.setStyle("fontSize", 10);

stop();
Another problem I have...
It seems that the code above load the combobox 5 times instead of one that I intend.
Why is that?
SOLUTION
Avatar of suqui
suqui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
is your PHP script URLEncoding its output by any chance?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi again...

I tested the textfile example but the output was the same as before. data=(rectangle) not the three letters. :(
When I the opened the textfile and saved it with UTF-8 encoding the characters where dsiplayed as the should. :)

The question is still how to get this working with my database example. That still doesn't work.
Here is the PHP code. The line utf8_encode($r_string); makes no difference whether its commented or not.
-----------------------
<?php
include("dbq.php");

$table = $HTTP_POST_VARS['tableName'];
$where = StripSlashes($HTTP_POST_VARS['whereCondition']);

$sql = "SELECT * from ".$table . $where;
$qr = mysql_query($sql, $db);

$r_string = 'n='.mysql_num_rows ($qr);
$i = 0;
while ($row = mysql_fetch_assoc ($qr)) {
  while (list ($key, $val) = each ($row)) {
    $r_string .= '&' . $key . $i . '=' . $val ;
  }
  $i++;
}

// utf8_encode($r_string);
echo $r_string.'&';
?>
Try using this as your php page and let us know how it goes :)

<?php

iconv_set_encoding("output_encoding", "UTF-8");

include("dbq.php");

$table = $HTTP_POST_VARS['tableName'];
$where = StripSlashes($HTTP_POST_VARS['whereCondition']);

$sql = "SELECT * from ".$table . $where;
$qr = mysql_query($sql, $db);

$r_string = 'n='.mysql_num_rows ($qr);
$i = 0;
while ($row = mysql_fetch_assoc ($qr)) {
  while (list ($key, $val) = each ($row)) {
    $r_string .= '&' . $key . $i . '=' . $val ;
  }
  $i++;
}
echo $r_string.'&';

?>
Hi again...

Tested it but unfortunately It didn't work... :(
Hmmm.......we've nailed it down to an encoding problem......now to find a working function!!
I'll have a look around and let you know if I find anything.

Cheers

-OBCT
Great...hope you find something!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi...perfect. Now its working...

My php version is 4.3.3.
What were the minor problems in my PHP script?
This was the only line that needed to change as I see it?
     echo $r_string.'&';
to
     $final_string = $r_string . '&';
     echo utf8_encode ($final_string);

"laughing" So you think my Flash code didn't quite make it to the finals in Coding styles championship....too bad.. =)
Well...since I've been testing this and learning Flash and Actionscript in like 2 days I think I've come a long way and thanks for making me understand how to code in Flash...
Just answer the question about what was wrong in my PHP-code and you got your points.
Thanks
>So you think my Flash code didn't quite make it to the finals in Coding styles championship....too bad.. =)

Untill about 2 weeks ago, I wouldn't have made it either :p lol

The few PHP errors........

$where = StripSlashes($HTTP_POST_VARS['whereCondition']);

should be

$where = stripslashes($HTTP_POST_VARS['whereCondition']);    //functions are case sensitive

------------------------

$sql = "SELECT * from ".$table . $where;

This would output the following SQL statement.

SELECT * FROM myCool_table myVariableName = "myValue";

UNLESS you had the "WHERE" in the $where variable.
Basically you should have used this....

$sql = "SELECT * from ".$table " WHERE " . $where;

Which would output...

SELECT * FROM myCool_table WHERE myVariableName = "myValue"

-----------------------

>Well...since I've been testing this and learning Flash and Actionscript in like 2 days I think I've come a long way and thanks for making me understand how to code in Flash...

Well done! :)
The hardest part about any programming language is learning all the functions and how everything works, such as 'for loops', 'prototypes', 'classes' and all that fancy hoo da.

Good luck with the rest of your project :)

Cheers

-OBCT
ok...

I copied the code from some example so the StripSlashes-error was not mine =)

Thanks...

I'll now try to validate every field in such way that when you change the selected value in the combobox it validates it and then set an image if it was correct or not.
Doesn't really know how to do this but I'll try to work it out...maybe I just have to change the state of an movieclip...