0
/*
        [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}]
            ],
        ]);
        */

I have a table and i need to get the output in this format back to Flex which i am not able too... can anyone point me where i am going wrong in my php which does not throw this output above.

PHP code:

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

I know that PHP does not have ArrayCollection.

Desired output from 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))
            ),

    );
1
  • The desired format looks like json to me. Is that what you're going for? Also, your code formatting is kind of scary ;) Vertical space is okay. Commented Nov 25, 2009 at 18:24

2 Answers 2

1

The final format that you've described looks like JSON. You might be able to just do

$projectData = getAllProjects();
...
$projectDataFormatted = json_encode($projectData);
Sign up to request clarification or add additional context in comments.

1 Comment

I was able to pass the same thing, and get the result in my other code... it looks json, buts its arrayCollection in Flex
0

Even if you successfully make a string that looks like an ArrayCollection and send it to flex, you still would have to parse it back at the flex side - you cannot just initialize an array collection from a string. Use json (which would be straightforward here, but you need a library to parse it at the flex side) or xml (flex has native support for e4x) instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.