Witam,

posiadam prostą bazę danych i potrzebuję wyświetlić jej zawartość w prezentacji flash. Problem polega na tym, że prawdopodobnie php nie obługuje mi utf-8. W ActionScripcie3 mam podane nazwy z pierwszej kolumny tabeli MySQL, są one wpisane z polskimi znakami, dane w tabeli są z polskimi znakami. Php otrzymując daną z AS3 sprawdza w bazie danych co kryje się w drugiej kolumnie dla danej z AS3 i przesyła ja do flasha który wyświetla to w prezentacji. Jeśli we flashu mam nazwę z polskimi znakami to wyświetla mi, że nie ma dla niej rekordów, jeśli nie ma polskich znaków to wszystko jet ok z tym, że zawartość drugiej kolumny wyświetla się we flash bez polskich znaków.
Aby wszystko zobrazować zamieszczam kody i screeny. Jeśli ktoś ma pomysł to proszę o pomoc.

  1. <?php
  2.  
  3. $username = $_POST['nazwa'];
  4.  
  5. // create connection
  6. $connection = mysql_connect("localhost", "root", "ppp") or die ("Couldn't connect to the server.");
  7.  
  8. // select database
  9. $db = mysql_select_db("serwis", $connection) or die ("Couldn't select database.");
  10.  
  11. // create SQL
  12. $sql = "SELECT kontakt FROM adresy where nazwa = '$username'";
  13.  
  14. // execute SQL query and get result
  15. $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");
  16.  
  17. // get number of rows in $result.
  18. $num = mysql_numrows($sql_result);
  19.  
  20. $phpConfirm = "";
  21.  
  22. $counter = 0;
  23.  
  24. while ($row = mysql_fetch_array($sql_result)) {
  25.  
  26. $domain = $row["kontakt"];
  27. if ($counter == 0) {
  28. $phpConfirm .= $domain;
  29. } else {
  30. // Use a item limiter "|" to seperate the records
  31. $phpConfirm .= "|" . $domain;
  32. }
  33.  
  34. $counter++;
  35. }
  36.  
  37. echo "phpConfirm=" . $phpConfirm . "&totalItem=" . $num;
  38.  
  39. // free resources and close connection
  40. mysql_free_result($sql_result);
  41. mysql_close($connection);
  42.  
  43. ?>



Kod ActionScript:

Kod
//Add Items to ComboBox
memberCombo.prompt = "Please select a user";
memberCombo.addItem( {label: "INCHCAPE MOTOR BMW" } );
memberCombo.addItem( {label: "POSŁUSZNY BMW Bydgoszcz" } );
memberCombo.addItem( {label: "BEST AUTO BMW Lublin" } );
memberCombo.addItem( {label: "TŁOKIŃSKI BMW Łódź" } );
memberCombo.addItem( {label: "M-CARS BMW Kraków" } );
memberCombo.addItem( {label: "BAWARIA MOTORS BMW" } );
memberCombo.addItem( {label: "AUTO FUS BMW Warszawa" } );
memberCombo.addItem( {label: "AUTO PREMIUM BMW Świlcza" } );
memberCombo.addItem( {label: "AUTO BRECZKO BMW Białystok" } );
memberCombo.addItem( {label: "ZDUNEK BMW Gdańsk" } );
memberCombo.addItem( {label: "AUTO CENTRUM SIKORA BMW Bielsko-Biała" } );
memberCombo.addItem( {label: "SMORAWIŃSKI I SPÓŁKA BMW Poznań" } );
memberCombo.addItem( {label: "BMW Bońkowscy" } );

//Add the Combo Header
//myDataGrid_dg.addColumn("Name");

//Add CHANGE event listener to ComboBox
//Whenever the index of Combox CHANGE, function checkComplete will be called
memberCombo.addEventListener(Event.CHANGE, checkComplete);

function checkComplete(evt:Event):void {

    // Create A new URLVariables instance to store the variable
    var myVariables:URLVariables = new URLVariables();
    
    // Create a variable (e.g. candidate) to send
    myVariables.nazwa = evt.target.value;
    
    // Create a new URLRequest instance sending data to "ascom01.php"
    var myRequest:URLRequest = new URLRequest("http://localhost/flash/apm01.php");
    
    // Send data using the POST method
    myRequest.method = URLRequestMethod.POST;
    
    // The data property of the request is set to the
    // URLVariables instance (myVariables) to send to the PHP file.
    // Note: myVariables stored the variable (e.g. candidate)
    myRequest.data = myVariables;
    
    // Create a new instance of the URLLoader class to work with.
    // URLLoader.load( ) method should be used when we need the
    // sent variables returned back to Flash ActionScript.
    var myLoader:URLLoader = new URLLoader;
    
    //specify dataFormat property of the URLLoader to be "VARIABLES"
    //This ensure that the variables loaded into Flash with the same variable names
    myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    
    //Load the PHP file by using URLRequest
       myLoader.load(myRequest);
    
    //Listen when the loading of data COMPLETE
    //Call the loadComplete function when the loading COMPLETE
    myLoader.addEventListener(Event.COMPLETE, loadComplete);
       
}



// This is the function that display the data returned back from PHP file
function loadComplete(evt:Event):void {
    
    //Display the value with variable name "totalItem"
    total_txt.text = evt.target.data.totalItem
    
    //Get the value (string) with variable name "phpConfirm"
    var myResult:String = evt.target.data.phpConfirm;
    
    //Split the string into an Array
    var myArray:Array = myResult.split("|");
    //output_txt.text = "The number of items are: " + myArray.length;
    
    //var finalString = "";
    
    // Clear the DataGrid
    myDataGrid_dg.removeAll();
    
    var i:int;

    for (i = 0; i < myArray.length; i++) {
        
        //Add the Items to DataGrid
        myDataGrid_dg.addItem( {Name: myArray[i]} );

    }
    
    //Set the width of the DataGrid (Not width of single column)
    myDataGrid_dg.width = 380;

    //The Height of row can be set in Parameter window, or
    myDataGrid_dg.rowHeight = 20;

    //Set number of row
    //Set equal to the number of row to auto fit the row
    myDataGrid_dg.rowCount = i;
    
    var textFormat1:TextFormat = new TextFormat();
    textFormat1.size = 12;
    textFormat1.color = 0x0000CC;
    textFormat1.bold = true;
    textFormat1.font = "Times New Roman"
    myDataGrid_dg.setRendererStyle("textFormat", textFormat1);
    
}




Jeśli jest nazwa bez polskich znaków to łączy się z bazą i wyświetla dane ale bez polskich znaków:
screen1

Jeśli są polskie znaki w nazwie to nie łączy się i pokazuje, że jest 0 rekordów:
screen2

Kofiguracja bazy:
baza1
baza2



Problem rozwiązany wystraczyło dodać " mysql_query("SET NAMES utf8"); " po mysql_connect

Temat do zamknięcia