1 Reply Latest reply on Aug 20, 2010 7:43 AM by juedvaga80

    Help with Flex and DropDownList

    juedvaga80

      Hello everybody, i need another help


      i'm triyng to do the next in flex: using DropDownListi and Mysql DB, I want select to a product from a DropDownList after i select a corresponding brand for example:

       

      * Coca Cola

        -- Coca Cola Light

        -- Coca Cola Zero

        -- Coca Cola Regular

      * Pepsi

        -- Pepsi Light

        -- Pepsi regular


      those are products that i have on my DB, i get see on my first DropDownList all brand's but i can select any product, because i don't know how made that relation between DropDownList's, here is my code, can any body help me? PLEASE ????

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                        xmlns:s="library://ns.adobe.com/flex/spark" 
                        xmlns:mx="library://ns.adobe.com/flex/mx" 
                        minWidth="500" minHeight="600" backgroundColor="#F4BE55" 
                        xmlns:employeeservice="services.employeeservice.*">
           <fx:Style source="Prueba8.css"/>
           <fx:Script>
                <![CDATA[
                     import com.adobe.serializers.utility.TypeUtility;
                     
                     import mx.controls.Alert;
                     import mx.controls.Text;
                     import mx.events.FlexEvent;
                     import mx.rpc.events.ResultEvent;
                     
                     import spark.events.IndexChangeEvent;
                     
                     protected function marDr_creationCompleteHandler(event:FlexEvent):void
                     {
                          getMarcaResult.token = employeeService.getMarca();
                     }
                     protected function proDp_creationCompleteHandler(event:FlexEvent):void
                     {
                          getProductoByMarcaResult.token = employeeService.getProductoByMarca('Pep');
                     }
      
                ]]>
           </fx:Script>
           
           <fx:Declarations>
                <s:CallResponder id="getMarcaResult"/>
                <employeeservice:EmployeeService id="employeeService" 
                fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
                       showBusyCursor="true"/>
                <s:CallResponder id="getProductoByMarcaResult"/>
           </fx:Declarations>
           <s:Label x="137" y="10" text="Prueba 1  -  Ejemplos" fontWeight="bold" fontSize="20"/>
           
           
           <s:DropDownList x="99" y="97" prompt="Selecciona Marca ..." 
                               width="169" id="marDr" 
                               creationComplete="marDr_creationCompleteHandler(event)" 
                               labelField="marca"
                               cornerRadius="7" 
                               borderColor="#BC660A" 
                               chromeColor="#C76F20" 
                               focusColor="#AA7A06" 
                               selectionColor="#DFA055" 
                               rollOverColor="#FFAB3E">
                <s:AsyncListView list="{getMarcaResult.lastResult}"/>
           </s:DropDownList>
           
      
           <s:DropDownList x="65" y="247" prompt="Seleccione el producto ..." 
                               id="proDp" width="205" 
                               creationComplete="proDp_creationCompleteHandler(event)"
                               labelField="ds_producto">
                <s:AsyncListView list="{TypeUtility.convertToCollection(getProductoByMarcaResult.lastResult)}"/>
           </s:DropDownList>
      
      </s:Application>
      

       

      and this is my service

       

      <?php 
      class EmployeeService { 
        var $username = "test"; 
        var $password = "12345"; 
        var $server = "192.168.0.194"; 
        var $port = "3306"; 
        var $databasename = "proyect"; 
        
        var $connection; 
        public function __construct() { 
          $this->connection = mysqli_connect( 
                             $this->server,  
                             $this->username,  
                             $this->password, 
                             $this->databasename, 
                             $this->port 
                             ); 
          
          $this->throwExceptionOnError($this->connection); 
        } 
      
        public function getMarca() {
           $stmt = mysqli_prepare($this->connection,
                "select co_marca,
                        no_marca
                 from cmm_d_marca");     
            $this->throwExceptionOnError();
            mysqli_stmt_execute($stmt);
            $this->throwExceptionOnError();
            $rows = array();
            mysqli_stmt_bind_result($stmt, $row->cod, $row->marca);
            while (mysqli_stmt_fetch($stmt)) {
                $rows[] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt,  $row->cod, $row->marca);
            }
            mysqli_stmt_free_result($stmt);
            mysqli_close($this->connection);
            return $rows;
        }   
        
      
        public function getProductoByMarca($searchStr) {
           $stmt = mysqli_prepare($this->connection,
                "select id_producto,
                        co_marca,
                        ds_producto
                from cmm_f_producto
                where co_marca like ?");
            $this->throwExceptionOnError();
            mysqli_stmt_bind_param($stmt, 's', $searchStr);
            $this->throwExceptionOnError();
            mysqli_stmt_execute($stmt);
            $this->throwExceptionOnError();
            $rows = array();
            mysqli_stmt_bind_result($stmt, $row->id_producto, $row->co_marca, 
                                    $row->ds_producto);
            while (mysqli_stmt_fetch($stmt)) {
                $rows[] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt, $row->id_producto, $row->co_marca, 
                                    $row->ds_producto);
            }
            mysqli_stmt_free_result($stmt);
            mysqli_close($this->connection);
      
            return $rows;
        }    
      } 
      ?>
      

       

       

      Please somebody help me i need a solution a soon as possible please . thank's.


      Juedvaga