获取Array Collection中的输出

时间:2009-11-25 18:17:19

标签: php flex

/*
        [Bindable]
        public var rows1:ArrayCollection=new ArrayCollection([
            ['Google',      [{Projectname:"1", Client:0},
                                {Projectname:"2", Client:1},
                                {Projectname:"3", Client:2},
                                {Projectname:"4", Client:3}]
            ],
            ['Yahoo',               [{Projectname:"1", Client:4},
                                {Projectname:"2", Client:1},
                                {Projectname:"3", Client:2},
                                {Projectname:"4", Client:1}]
            ],
        ]);
        */

我有一张桌子,我需要将这种格式的输出恢复到Flex,我也不能...有人能指出我在我的PHP出错的地方,不会抛出上面的输出。< / p>

PHP代码:

public function getAllProjects()
{
    $findings=array();
    $sql="SELECT id,projectname FROM project";
    $result=mysql_query($sql);
    if(!$result)
    {
        throw new Exception("QUERY FAILED.\n\n".mysql_error());
    }
    while(list($id,$projectname)=mysql_fetch_row($result))
    {
        $dataArray=array();
        $sql="SELECT state AS state FROM project WHERE id= '$id'";
        $result2=mysql_query($sql);
        if(!$result2)
        {
            throw new Exception("QUERY FAILED.\n\n".mysql_error());
        }
        while($row=mysql_fetch_array($result2))
        {
            $dataArray[]=$row;
        }
        $findings[]=array($projectname,$dataArray);
    }//while
    return $findings;
}

我知道PHP没有ArrayCollection。

PHP的所需输出

$rows=array(
        array('ssss1232',array(array("projectname"=>"1", "clientname"=>0),
            array("projectname"=>"2", "clientname"=>1),
            array("projectname"=>"3", "clientname"=>3),
            array("projectname"=>"4", "clientname"=>3))
            ),
            array('sssss',array(array("projectname"=>"1", "clientname"=>0),
                    array("projectname"=>"2", "clientname"=>1),
                    array("projectname"=>"3", "clientname"=>2),
                    array("projectname"=>"4", "clientname"=>1))
            ),

    );

2 个答案:

答案 0 :(得分:1)

您描述的最终格式类似于JSON。你或许可以做到

$projectData = getAllProjects();
...
$projectDataFormatted = json_encode($projectData);

答案 1 :(得分:0)

即使你成功地创建一个看起来像ArrayCollection的字符串并将其发送到flex,你仍然需要在flex端解析它 - 你不能只是从字符串初始化一个数组集合。使用json(这里很简单,但你需要library在flex侧解析它)或xml(flex支持e4x)而不是。