mardi 23 juin 2015

Get values of a php in AS3

I've managed to get a value from a sql table in my AS3 code, but I don't understand why I can't get a second value.

In my php file I've got :

// create SQL
 $sql = "SELECT * FROM dt_base where username = '$username'";

// execute SQL query and get result
 $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");

// get number of rows in $result.
 $num = mysql_numrows($sql_result);

$phpConfirm = "";
$phpConfirmSecond = "";
$counter = 0;

while ($row = mysql_fetch_array($sql_result)) {

 $up= $row["up"];
 $down= $row["down"];
 if ($counter == 0) {
 $phpConfirm .= $up;
 $phpConfirmSecond .= $down;

 } else {
 // Use a item limiter "|" to seperate the records
 $phpConfirm .= "|" . $up;
 $phpConfirmSecond .= "|" . $down;
 }
 $counter++;
 }
?> 

And in my AS3 code :

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;
    trace(evt.target.data.phpConfirm);

    var myResultSecond:String = evt.target.data.phpConfirmSecond;
    trace(evt.target.data.phpConfirmSecond);


//Split the string into an Array
    var myArray:Array = myResult.split("|");
    var myArraySecond:Array = myResultSecond.split("|");

    var finalString = "";
    var finalStringSecond = "";
    var i:int;

    for (i = 0; i < myArray.length; i++) {

        finalString = finalString + myArray[i] + "<br>";
        finalStringSecond = finalStringSecond + myArraySecond[i] + "<br>";
    }

    output_txt.htmlText = finalString;
    output_txtSecond.htmlText = finalStringSecond;
}

trace(evt.target.data.phpConfirm) results with the value of "up", so it's working. But trace(evt.target.data.phpConfirmSecond) results with "undefined" instead of the value of "down".

Any idea why ?

Aucun commentaire:

Enregistrer un commentaire