I need to select game's number from MySql database and pass It to Flash game (ActionScript 3).
For now I have AS3 code:
function getVars(e:Event):void{
var req:URLRequest = new URLRequest("top.php");
var loader:URLLoader = new URLLoader(req);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, getVarComplete);
}
function getVarComplete(e:Event):void{
var gameNr.text = e.target.data;
}
And here is PHP code (I don't know how selected row pass to variable and send It to flash)
$id = $_SESSION['id'];
$mysqli = new mysqli("localhost","xxx","xxx","xxx");
$query = "SELECT GameNr
FROM Game
WHERE FBId = '". mysql_real_escape_string($id) ."'
ORDER BY PlayTime DESC LIMIT 1";
UPDATE:
If I use following PHP:
<?php
session_start();
$id = $_SESSION['id'];
$mysqli = new mysqli("localhost","xx","xx","xx");
$query = "SELECT GameNr
FROM Game
WHERE FBId = '". mysql_real_escape_string($id) ."'
ORDER BY PlayTime DESC LIMIT 1";
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
}
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
echo $row["GameNr"];
}
$result->free();
}
$mysqli->close();
?>
www.myhost.com/top.php returning correct value NA==
If I use following AS3 code:
function onVarsLoaded(e:Event) {
var msg:String = "Communication with the server was successful.\n\n";
msg += "foo -> "+e.target.vars.foo+"\n";
trace(msg);
}
It returning me: foo -> undefined
If I change this
msg += "foo -> "+e.target.vars.foo+"\n"; to
msg += "foo -> "+e.target.vars+"\n";
It returning me incorrect value: foo -> NA=%3D