I have a Mysql database and I am trying to import multiple records with multiple columns into Flash AS3 using PHP. My problem is I am able to make it work with a single column and multiple records but for multiple columns I am not being able to format it correctly. What i wish to have is an array(of records) of associative arrays(of columns) i.e. I want to be able to partition the output (from php) based on '|' and store it in a flash array and then be able to access name,id for each of them (see below the code).
the php part ->
<?php
......//connection to mysql db ...etc.
$result = mysql_query($sql);
$output = "success=$db&myArrayForFlash=";
//error check
...
//form the return string
while($myRow = mysql_fetch_assoc($result)){
$arrayElement = "&name=".$myRow['name'];
$arrayElement = $arrayElement."&id=".$myRow['id'];
$output = $output."$arrayElement" . "|";
}
}
echo($output);
?>
the flash part->
function completeHandler(e:Event):void
{
if(e.target.data.success=="1"){
var myArray:String = e.target.data.myArrayForFlash; //empty
var myCol:String = myArray[0]['id'];
this.var= e.target.data.myArrayForFlash.split("|");
//do something else
}
else
{
Alert.show("Query failed.
");
}
}
the problem is I get an array of names,id but the myArrayForFlash is empty (which is kind of expected).Is there any way to get past this?
I am a total newbie to flash/php so any help is useful!
Here's a reference and another that I used. (I tried searching for something similar but all I get is returning multiple rows with 1 column or 1 row with multiple columns)
function createList(names: Array, ids: Array):Object{
if(names.length != ids.length){
trace('incorrect input');
return null;/*you may throw an error as well*/
}
var hash:Object = new Object();
for(var i: int = 0; i < names.length; i++){
hash[ids[i]] = names[i];/*or hash[names[i]] = ids[i] if name is a key*/
}
return hash;
}
upd:
function createList(names: Array, ids: Array):Array{
if(names.length != ids.length){
trace('incorrect input');
return null;/*you may throw an error as well*/
}
var hash:Array = new Array();
for(var i: int = 0; i < names.length; i++){
hash.push({id:ids[i], name:names[i]});
}
return hash;
}