0
votes

I've searched around and couldn't quite find the answer to my question. What is the best way to populate a multiple Comboboxes when using Flex 4.5 and PHP 5?

I am developing a Flex app that displays about 20 Comboboxes on the screen - each combo showing different data. I would like all of the comboboxes to be populated at once when the app starts. I used the default "Data/Service" wizard in Flex that automatically creates the PHP that returns an ArrayCollection to Flex. For example, below is the current PHP function I use that populates each ComboBox:

public function getListsByCODE($code) {

    $stmt = mysqli_prepare($this->connection, "SELECT a.IDCODE, a.CODE, a.DESCR, a.NOTES FROM DROPDOWN_VW a WHERE (a.CODE = ?)");
    $this->throwExceptionOnError();

    mysqli_stmt_bind_param($stmt, 's', $code);
    $this->throwExceptionOnError();

    mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();

    $rows = array();

    mysqli_stmt_bind_result($stmt, $row->IDCODE, $row->CODE, $row->DESCR, $row->NOTES);

    while (mysqli_stmt_fetch($stmt)) {
        $rows[] = $row;
        $row = new stdClass();
        mysqli_stmt_bind_result($stmt, $row->IDCODE, $row->CODE, $row->DESCR, $row->NOTES);
    }

    mysqli_stmt_free_result($stmt);
    mysqli_close($this->connection);

    return $rows;
}

This works fine... except I have to submit 20 calls from Flex - each call returning different data for each combobox - which creates massive overhead.

I was thinking of returning ALL the rows from the database (using one call) and then using a method in Flex to easily parse (e4x?) through the data to specifically populate each combobox. For example, my rows of data may look like the following:

CODE    DESCR
------- -----------
Fruit   Apple   
Fruit   Orange
Drink   Soda
Drink   Water
Drink   Wine
Candy   Gummy Bears

If there someway in Flex where I can (easily) convert the ArrayCollection to XML and use e4x to populate the dataProvider with something like "...lastResult[Food='Fruit']"

or

Have PHP return XML in a way that the Flex lastResult will be a XMLListCollection (assuming that's what I need for e4x)?

or

Have PHP correctly return a multidimensional ArrayCollection where I can directly reference the "Fruit" collection? With this question I tried the following PHP code:

I modified "$rows[]=$row;" to "$rows[$rows->CODE][]=$row;" in the above code.

This looked like it works - PHP sends an ArrayCollection with a Fruit collection, Drink collection and so on (I see this when using the 'Test Operation' in Flex) - but I get a Flex error (TypeError: Error #1034: Type Coercion failed: cannot convert []@143f1b29 to mx.collections.IList) when trying to reference the object:

dataProvider="...lastResult.source.Fruit"

or

Is there a more efficient way?

Anyone have any ideas? Thank you very much.

1

1 Answers

0
votes

I'm a Flex idiot, mind you, but if I were to do this, and I had an ArrayCollection - well, the rest seems cake: each combo box would have it's own datasource; initialize those datasources (an array of them, for instance, to make it easy); iterate through the ArrayCollection, populating the datasources (correspondence between ArrayCollection column index and the array index of each datasource, of course, would make this very easy). At least it seems to me that's how you could do it. Probably this response is too late though :(