5 Replies Latest reply on Mar 1, 2010 10:45 AM by cheftimo

    Regarding - ComboBox

    venkatsyss

      hi,

       

      My question how to display the data base values in combo box.

       

      I have used httpservice  and the id is userRequest url is combox.php.In the combo.php i fetch the values from the database and returned it.

       

      My query is:

       

      <?php
      $con=mysql_connect("localhost","root","");
      if(!$con){
          echo "Error in Connecting Database";
      }
      mysql_select_db("project",$con);

       

      $sql="select * from tbl_member";
      $result=mysql_query($sql);

       

      print"<users>";

       

      while($row=mysql_fetch_object($result)){
         
          print "<user>
          <userid>".$row->member_id."</userid>
          <username>".$row->member_fname."</username>
          </user>";
      }

       

      print"</users>";

       

      ?>

       

      In the Httpservice i have call a function in the result  method.In the function i have declare a array and assigned the values to the arrays.The follwoing code shows:

       

      ans=event.result.users.user;

       

      But the result to fails to display in the combo box.

       

      Here my code in the comboBox:

       

      <mx:HBox>
              <mx:Label text="DisplayName"></mx:Label>
              <mx:ComboBox id="empId" dataProvider="{ans}" >
              </mx:ComboBox>
          </mx:HBox>

       

      Answer shows in the browser is [object object]

       

      Please provide me the solution to solve the problem.

       

      Thanks and Regards,

      venkat.R

        • 1. Re: Regarding - ComboBox
          cheftimo Level 2

          I don't know PHP, but I gather your Htppservice is returning a query containing the usernames and IDs. If that is the case, try something like this (I am assuming ans is a bindable ArrayCollection):

           

          In your result handler,

          ans = event.result as ArrayCollection

           

          in your <mx:ComboBox>,

          labelField = "username"

           

          HTH,

           

          Carlos

          • 2. Re: Regarding - ComboBox
            venkatsyss Level 1

            hi,

             

            Thanks for you reply .i got it the answer in a  successful manner.

             

            Another question is,

             

            I have to display the username in the combo Box .If the  user is selected a username in the Combobox we can display all the text input and the value in the text input.

             

            I tried in the above manner but i could not able to get it.

             

            <mx:states>
                <mx:State name="eShow">
                    <mx:AddChild>
                        <mx:Panel>
                            <mx:TextInput id="temp">
                               
                            </mx:TextInput>
                        </mx:Panel>
                    </mx:AddChild>
                </mx:State>
            </mx:states>

             

            //this function is have called in the combo box in the change mwthod.

            private function show(event:Event):void{
                              
                        currentState="eShow";
                        temp.text=event.currentTarget.selectedItem.username;
                     
                    }

             

            But i could not able to print the corresponding value in the textinput.

             

            Please find me the solutions to solve the problem.

             

            Thanks and Regards,

            venkat.R

            • 3. Re: Regarding - ComboBox
              cheftimo Level 2

              venkat:

               

              This should work in private function show():

               

              temp.text = "{empId.selectedItem.username}"

               

              Salud,

               

              Carlos

              • 4. Re: Regarding - ComboBox
                venkatsyss Level 1

                hi,

                 

                Thanks for your kind reply.But  it fails to display the result in the corresponding textinput.

                 

                 

                Thanks and Regards,

                venkat.R

                • 5. Re: Regarding - ComboBox
                  cheftimo Level 2

                  venkat:

                   

                  Is 'username' the correct name of the parameter?

                   

                  Try this:

                   

                  temp.text = "{empId.selectedItem}"

                   

                  If that doesn't work either, show the code for the ComboBox, the show() function and how you are using that function.

                   

                  Carlos