4 Replies Latest reply on Apr 6, 2009 4:38 AM by TodLoch

    How to populate DataGird with data returned from php page?

    TodLoch

      Hi, I'm new in Flex, I try to populate DataGrid with data from PHP, My code is

       

       

      <mx:HTTPService

       

       

      id="personRequest" result="getPerson(event)" url=http://localhost/searchPerson.php useProxy="false" method="POST"

      showBusyCursor="

      true" resultFormat="e4x">

      </

       

      mx:HTTPService>

       

       

      <mx:DataGrid

       

       

      id="searchResult" dataProvider="{???what to paste here???}" y="30"

      >

       

       

       

      </mx:DataGrid>

       

      .....

       

      private

       

       

      function getPerson(evt:ResultEvent):void {

       

      var res:XMLList = evt.result..dane as XMLList;

      searchResults =

      new XMLListCollection(res);

       

      }

       

       

      ....

      output from PHP

       

      <person>

      <dane>

      <name>ABC</name>

      <street>XLXXLX</street>

      </dane>

      <dane>

      <name>DEF</name>

      <street>YAYAYAY</street>

      </dane>

      </person>

       

      If I set the dataProvider as "searchResults" it doesn't work. I probably have to set as dataprovider any ArrayCollection , but I don't know how to convert my XMLListCollection to it.

       

      Could anyone help me populate Datagrid with

      name | streer

      ABC, XLXXLX

      DEF, YAYAYAY

       

      Best Regards,

      Mariusz

       

       

       

        • 1. Re: How to populate DataGird with data returned from php page?
          FangAvatar

          private function getPerson(evt:ResultEvent):void
          {
                     xmldata = (evt.result as XML);
                  
          }

           

          <mx:DataGrid

           

           

          id="searchResult" dataProvider="{xmldata.dane}" y="30"

          >

           

           

           

          </mx:DataGrid>

          • 2. Re: How to populate DataGird with data returned from php page?
            TodLoch Level 1

            Thanks for your reply, but I'm afraid it doesn't work :-( Could you browse my code and check what I'm doing wrong???

             

            full mxml code:

             

             

             

             

             

             

             

             

             

             

             

             

             

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

            <mx:Application

             

            xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="personRequest.send()">

            <mx:Script>

            <![CDATA[

             

             

                 import mx.rpc.events.ResultEvent;

             

                 [

            Bindable]

             

             

                 public var searchResultsXML:XML;

             

             

                 private

             

            function getPerson(evt:ResultEvent):void

             

                  {

                      searchResultsXML = (evt.result

            as XML);

             

             

                      trace(searchResultsXML);

                 }

             

            ]]>

            </mx:Script>

             

             

            <mx:HTTPService

             

            id="personRequest" result="getPerson(event)" url=http://localhost/searchPerson.php useProxy="false"

            method="POST" showBusyCursor="true" resultFormat="e4x">

            </mx:HTTPService>

             

             

            <mx:DataGrid

             

            id="searchResult" dataProvider="{searchResultsXML.dane}">

            </mx:DataGrid>

             

             

            </mx:Application>

             

            trace statement returns:

             

            <person>

            <dane>

            <id>1</id>

            <nazwisko>Topczewski</nazwisko>

            <imie>Mariusz</imie>

            <imie2/>

            <miejscowosc>Bia?ystok</miejscowosc>

            <ulica>Nowogródzka</ulica>

            <dom>7B</dom>

            <lokal>25</lokal>

            </dane>

            <dane>

            <id>1</id>

            <nazwisko>Topczewski</nazwisko>

            <imie>Mariusz</imie>

            <imie2/>

            <miejscowosc>Bia?ystok</miejscowosc>

            <ulica>Sybiraków</ulica>

            <dom>15</dom>

            <lokal>27</lokal>

            </dane>

            </person>

             

             

            • 3. Re: How to populate DataGird with data returned from php page?
              FangAvatar Level 1

              <mx:columns>
              <mx:DataGridColumn id="id" dataField="id" headerText="id"/>
              <mx:DataGridColumn  id="nazwisko" dataField="nazwisko" headerText="nazwisko"/>
              <mx:DataGridColumn id="imie" dataField="imie" headerText="imie"/>
              <mx:DataGridColumn  id="imie2" dataField="imie2" headerText="imie2"/>
              <mx:DataGridColumn id="miejscowosc" dataField="miejscowosc" headerText="miejscowosc"/>
              <mx:DataGridColumn  id="ulica" dataField="ulica" headerText="ulica"/>
              <mx:DataGridColumn id="dom" dataField="dom" headerText="dom"/>
              <mx:DataGridColumn  id="lokal" dataField="lokal" headerText="lokal"/>
              </mx:columns>

               

              After datagrid you post the above code.

              • 4. Re: How to populate DataGird with data returned from php page?
                TodLoch Level 1

                Thanks, it works!

                Best regards,

                Mariusz