5 Replies Latest reply on Jun 24, 2010 7:54 AM by djh88ukwb

    AMFPHP and datagrid

    djh88ukwb Level 1

      Hello All.


      I am trying to use AMFPHP with mysql and a flex app whilst outputting the data to a datagrid.  I am looking to see if anyone can give me an example.


      THis is what i want to do really.


      Have a php script look at my mysql database, look in the table named "jobs" and pull three fields "jobref" "company" "position".


      I would then like flex to use AMFPHP to pull all that, and chuck it straight into a datagrid.


      If anyone could help that would be great.  I need help with both the php script and flex part.


        • 1. Re: AMFPHP and datagrid
          David_F57 Level 5



          I can make a fake db to set up a simple class for you what is the structure integer/string/string or is jobref also a string ?




          • 2. Re: AMFPHP and datagrid
            David_F57 Level 5



            Its getting late so I just made the assumption that all fields were varchar (shouldn't really effect much)


            php file   called jobs.php (to be placed in the amfphp services folder)


            place your db settings as required in the variables host/name/user/pwd . depending on the way the server is setup you can usually just leave db_host as localhost.



            class jobs


            var $db_host = 'localhost';

            var $db_name = 'jobs';

            var $db_user = 'root';

            var $db_pwd = '';


            function jobs()



            $this->methodTable = array(

            "getJobs" => array(

            "description" => "Info Database",

            "access" => "remote"





            function getAllJobs()


            $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

            mysql_select_db( $this->db_name);

            $Query = "SELECT * from info";

            $Result = mysql_query( $Query );

            return( $Result );





            the application  in db_services.endpoint change the localhost to your URL. ie mydomain.com


            <?xml version="1.0" encoding="utf-8"?>

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">



            import mx.collections.ArrayCollection;

            import mx.events.FlexEvent;

            import mx.rpc.events.FaultEvent;

            import mx.rpc.events.ResultEvent;


            [Bindable] private var userArr:ArrayCollection = new ArrayCollection();


            protected function application1_creationCompleteHandler(event:FlexEvent):void


            db_services.endpoint = "http://localhost/amfphp/gateway.php";

            db_services.source = "jobs";

            db_services.destination = "amfphp";




            private function qryJobs(res:ResultEvent):void


            userArr = res.result as ArrayCollection;



            protected function db_services_faultHandler(event:FaultEvent):void


            // Alert.Show("something went wrong")






            <mx:RemoteObject id="db_services" fault="db_services_faultHandler(event)" showBusyCursor="true">

            <mx:method name="getAllJobs" result="qryJobs(event)"/>



            <mx:DataGrid x="145" y="192" width="567" dataProvider="{userArr}">


            <mx:DataGridColumn headerText="Job Ref" dataField="jobref"/>

            <mx:DataGridColumn headerText="Company" dataField="company"/>

            <mx:DataGridColumn headerText="Position" dataField="position"/>





            • 3. Re: AMFPHP and datagrid
              djh88ukwb Level 1

              Hey, Thanks for this, its really great !  Works well and alot easier.


              Tell me, could you help me post data to a combo box / Drop down list?


              All i get back is [object] [object]


              Taking the example before, how would i get it so the drop down list displays all of one field.


              Here is what i got so far.


              Added some php


              function getAllLinkedCompany()
              $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
              mysql_select_db( $this->db_name);
              $Query ="SELECT * from usernames WHERE assignedrecruiter ='7'";
              $Result = mysql_query( $Query );
              return( $Result );


              Added all the nessecary extra flex code i.e. the extra getOperation, extra arraycollection and results.


              Here is the results i have

                          private function qryLinked(res:ResultEvent):void           
                              linkedArr = res.result as ArrayCollection;           


              and the code for combo box


                  <s:ComboBox x="732" y="192" dataProvider="{linkedArr}"/>
                  <s:DropDownList x="732" y="234" width="146" dataProvider="{linkedArr}"></s:DropDownList>


              As i say all it returns is [object] [object]


              Any suggestions?

              • 4. Re: AMFPHP and datagrid
                David_F57 Level 5



                When passing an object/arrayCollection to the combo box you need to tell it what field you want


                <s:ComboBox x="732" y="192" dataProvider="{linkedArr}" labelField="username"/>


                i just used username but what ever the field name is use it...





                • 5. Re: AMFPHP and datagrid
                  djh88ukwb Level 1

                  Thank you


                  One last questions sorry


                  If i was pulling the labelField "username"  and then using the following code to push it to php


                              private function createNewJob():void
                                  newcreateJobRefInput = createJobRefInput.text;
                                  newcreateCompanyInput = createCompanyInput.text;
                                  newcreatePositionInput = createPositionInput.text;
                                  createJobRefInput.text = "";
                                  createCompanyInput.text = "";
                                  createPositionInput.text = "";


                  Here i am taking the value of the input - which is "createCompanyInput" (combo box id)


                  But i would like to send a different value to the php script.


                  Basically what i want to do, the user selects a company name from the drop down box, but the ID number gets sent in the script instead of the name, so there needs to be some sort of script to swap them over.


                  COuld you help with this ?  Do you understand what i mean ?