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.
<?php $username = $_POST['nazwa']; // create connection // select database // create SQL $sql = "SELECT kontakt FROM adresy where nazwa = '$username'"; // execute SQL query and get result // get number of rows in $result. $phpConfirm = ""; $counter = 0; $domain = $row["kontakt"]; if ($counter == 0) { $phpConfirm .= $domain; } else { // Use a item limiter "|" to seperate the records $phpConfirm .= "|" . $domain; } $counter++; } // free resources and close connection ?>
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);
}
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