Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在数组集合中获取输出_Php_Apache Flex - Fatal编程技术网

Php 在数组集合中获取输出

Php 在数组集合中获取输出,php,apache-flex,Php,Apache Flex,我有一个表,我需要得到这个格式的输出回到Flex,我不能太。。。谁能告诉我我的php哪里出了问题,它没有把这个输出放在上面 PHP代码: /* [Bindable] public var rows1:ArrayCollection=new ArrayCollection([ ['Google', [{Projectname:"1", Client:0}, {Proje

我有一个表,我需要得到这个格式的输出回到Flex,我不能太。。。谁能告诉我我的php哪里出了问题,它没有把这个输出放在上面

PHP代码:

/*
        [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}]
            ],
        ]);
        */
我知道PHP没有ArrayCollection

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;
}

您描述的最终格式类似于JSON。你也许可以这样做

$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))
            ),

    );

即使您成功地创建了一个看起来像
ArrayCollection
的字符串并将其发送给flex,您仍然需要在flex端对其进行解析—您不能仅从字符串初始化数组集合。使用json(这在这里很简单,但您需要一个在flex端解析它的方法)或xml(flex本机支持
e4x
)。这就是你想要的吗?而且,您的代码格式有点可怕;)垂直空间是可以的。我能够通过同样的东西,并在我的其他代码中得到结果。。。它看起来像json,但在Flex中是arrayCollection
$projectData = getAllProjects();
...
$projectDataFormatted = json_encode($projectData);