4 Replies Latest reply on Jan 30, 2010 6:30 PM by Matt Le Fevre

    Xml data from PHP not displaying in datagrid

    DrDTP

      I have looked at the forum for answers to my problem and tried to copy and paste from developers in the Adobe cookbooks and other websites. I have also looked at developer videos on Adobe with no luck. So here is my code.

       

      My php code was tested in Dreamweaver using a Mysql database. When I open the php page I see the data displayed. A review of the page source shows the following:

       

      <users><user><userid>2</userid><lastname>Price</lastname><firstname>David</firstname></user></users>

       

      It looks like good xml. There are no html display elements in the php file, this was for testing the php code only.

       

      Now to Flex 3 developed in Flex 3 builder.

       

      I use an HTTPService in Flex to call for these data from a module that loads in the application like this.

       

      Application:

       

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

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" color="#EEEEEE" width="100%" height="100%" backgroundGradientColors="[#CCCCCC, #EEEEEE]" backgroundColor="#000099" creationComplete="loadinitmodule()">

      <mx:Script>

      <![CDATA[

      import mx.modules.Module;

      import mx.modules.IModuleInfo

      import mx.modules.ModuleManager

      import mx.events.ModuleEvent

      private var m_info:IModuleInfo

      private var m_header:IModuleInfo

      public function loadinitmodule():void {

      m_info= ModuleManager.getModule("CGIndex.swf");

      m_info.addEventListener(ModuleEvent.READY, modEventHandler);

      m_info.load(ApplicationDomain.currentDomain);


      m_header= ModuleManager.getModule("CGIndexHeader.swf");

      m_header.addEventListener(ModuleEvent.READY, headerEventHandler);

      m_header.load(ApplicationDomain.currentDomain);

      }

      private function modEventHandler(e:ModuleEvent):void{   Location of the HTTPService and datagrid. See below.

      mainCanvas.addChild(m_info.factory.create() as Module);

      }

      private function headerEventHandler(e:ModuleEvent):void{

      headerCanvas.addChild(m_header.factory.create() as Module);

      }


      ]]>

      </mx:Script>

      <mx:Canvas id="headerCanvas" width="99%" height="150">

      </mx:Canvas>

      <mx:Canvas id="mainCanvas" width="99%" height="450">

      </mx:Canvas>


      </mx:Application>

       

      The modules load without a problem.

       

      HTTPService:

       

      <mx:HTTPService id="loginService" url="flex_xmltest.php" />

       

      where "flex_xmltest.php" is the php file that produces the xml. It is in the src folder with the .swf files. At runtime it is in the bin-debug folder.

       

      I call for the send function for the HTTPService on the creationComplete event of the module like this.

       

      creationComplete="doSend()"


      <mx:Script>

      <![CDATA[

      private function doSend():void{

      loginService.send();

      }

      ]]>

      </mx:Script>

       

      I have used absolute url and relative url. The absolute url throws and error that says the resource cannot be found. The relative url throws no error and displays the application in the browser but does not display data in the datagrid.

       

      I set the datagrid dataprovider property like this.

       

              <mx:DataGrid id="userGrid" dataProvider="{loginService.lastResult}" >

      <mx:columns>

      <mx:DataGridColumn headerText="Last Name" dataField="lastname"/>

      <mx:DataGridColumn headerText="First Name" dataField="firstname"/>

      </mx:columns>

      </mx:DataGrid>

       

      The datagrid will be visible in the browser. The headers are correct but no data in the columns. Why? I created the service with a valid url. I called for the service. I set the dataprovide property to the service. It should work but it doesn't.

       

      Thanks in advance for your help,

       

      David

        • 1. Re: Xml data from PHP not displaying in datagrid
          aktell2007 Level 1

          Hi there,

           

          I'm not sure where you got this code from but!

           

          First up I like to say you do not need the App. code to display as the module is the one which is important, and if the module loads without a pronblem than it should be in the module code!because this is where the HTTP call etc. is!

          By the way the module code is quiet complycated as is, but than Flex 3 has 1001 ways of doing things.

           

          Looking at your HTTP Service

          <mx:HTTPService id="loginService" url="flex_xmltest.php" />
          

           

          I would say there is something missing that is why I was asking about the code as such! and what is missing is the 'sesultFormat' property and the 'method' property for starter.

          Not knowing the php code the 'method' property has to indicate in Php and in Flex as 'GET' or 'POST'.

          It is also unclear to me if your Php is creating the Xml or if you use MySQL data through Php/Xml to the Flex App.

           

          Further you did not have any 'request' section in your HTTP call. E.G.

          <mx:request>
          <userid>{userid.text}</userid>
          <firstName>{firstName.text}</firstName>
          <lastName>{lastName.text}</lastName>
          </mx:request>
          

           

          And last but not least you maybe should use in your DataGrid:

          dataProvider="{loginService.lastResult.user}" >
          

           

          regards aktell

          • 2. Re: Xml data from PHP not displaying in datagrid
            DrDTP Level 1

            Aktell,

             

            Thanks for your answer but unfortunately it does not work. There are several issues.

             

            • I did not assign the request property because I did not pass any parameters to the query in php.
            • I did not assign the method property because I did not pass any parameters to the query in php.
            • I used dataProvider="{loginService.lastResult.users.user}" as a property assignment in the control and I also tried to assigned it in a function. Neither worked.

            If you have other ideas let me know.

             

            David

            • 3. Re: Xml data from PHP not displaying in datagrid
              aktell2007 Level 1

              Hi again,

               

               

              I think reading your last tread that your problem lies much deeper and I would suggest that you maybe return to basics on that, maybe consulting the HELP section for Flex!

              Using an HTTP Service "I did not assign the request property because I did not pass any parameters to the query in php" how is it with returning a parameter to FLEX maybe 'Xml, text, e4x etc.' how could it work otherwise - it works both ways!

              And if you check on details about the 'method' property you find a lot of helpful tips! Further more I have seen on the Net many examples of how to, but none had NO 'resultFormat' etc. at all missing.

              Why don't you try it the way it would work for sure, and than try to modify it towards your way of thinking! later?

               

              I just finished an App. which has everything 'Sending-Returning-Create-Insert-Select-Replace-Copy and BackUp Tables etc.' including ShoppingCart using Flex, Php(DOM type Xml), MySQL etc. etc. and all and every one of the Php-Xml script work smoothly.

               

              regards aktell

              • 4. Re: Xml data from PHP not displaying in datagrid
                Matt Le Fevre Level 4

                Post a sample of the XML you're trying to load into the datagrid