5 Replies Latest reply on Jul 14, 2009 3:40 PM by trmnshwrx

    Flex not understanding ArrayCollection passed from PHP

    trmnshwrx

      First, I'm using Flex Builder 3, Wamp with PHP 5.2.9-2 and MySQL 5.1.33.  I'm also using the Zend Framework to get data from MySQL.

       

      I have Flex using an HTTPService to send a request; the server then executes some PHP that reads a MySQL database, writes each row into an array, all the rows into an array.  Though I have changed the actual data, here's what my a call on my MySQL database returns:

      SELECT  *
      FROM  `table1`
      LIMIT 0 , 30

       

      1     VideoDescription     filename.flv

      2     otherDescription      filename2.flv

      3     thirdDescription       filename3.flv

       

      The names of the columns are "id", "title", and "source", respectively.

      The arrays in php seem to work fine, because in PHP,

      print($result[1]['title']);

      will give us "otherDescription", and we can see that easily in Flex.

       

      The problem is that I don't want "otherDescription"; I want the whole table passed to Flex as an array collection.

      I am able to pass the array from php, and then it is just an "Array" that I can't do anything with.  No matter what I trace from it, it always says "Array", or it simply does not work...why is this?  Why can't I get anything out of it?  The only useful thing I can pass from PHP to Flex is a String, and that's kind of awkward for what I'm doing.

       

      Here's my PHP code:

       

      <?php

           require('Zend/Db/Adapter/Pdo/Mysql.php');

           $arr = array('host' => '127.0.0.1','username' => 'root','password' => '','dbname' => 'videolist');

           $db = new Zend_Db_Adapter_Pdo_Mysql($arr);

           $db->getConnection();

           $sql = 'SELECT * FROM `table1` LIMIT 0 , 30';

           $result = $db->fetchAll($sql, 2);

           $resultArray = array();

           foreach($result as $resultItem){

                foreach($resultItem as $itemFragment){

                     $resultArrayFragment[] = $resultItem;

                }

                $resultArray[] = $resultArrayFragment;

           }

           echo $result;  // or, to illustrate the way the array collection works, we can put "$result[1]['title'];", in which case, Flex will show "otherDescription"

                                   //  for the traces below

      ?>

       

       

      Here's my relevant ActionScript:

       

      private function onResult():void{     //this is fired as we get a result after calling the HTTPService send()

           var result = userRequest.lastResult;

           trace("trace 1 = " + String(userRequest.lastResult));     // produces: "Array"

           trace("trace 2 = " + result[1]["title"]);                           // produces: "Array"

           trace("trace 3 = " + result[1]["title"][0][0][0][0]);            // STILL just produces: "Array"

           var someDataProvider:ArrayCollection = new ArrayCollection(userRequest.lastResult.valueOf());

          trace("trace 4 = " + result[0]);                                     // produces: "RangeError: Index '1' specified is out of bounds..."

       

      .

      .

      .

      }