doujinai2183 2011-02-22 17:34
浏览 54

从PHP发送多行x cols到Flash

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)

  • 写回答

1条回答 默认 最新

  • duanke1984 2011-02-22 21:03
    关注
    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了