Read Data from Database into DataGrid Control: PHP backend

As we know that flex app reads data in the form of XML, so we have to send data from PHP page in the form of XML.So that it can be embed into the datagrid control.

So the PHP page looks like this below, which generates XML lookslike data.

echo “<product>”;

echo “<items>”;
echo “<name1>”Kumar”</name>”;
echo “<name2>”Gandhi”</link>”;
echo “</items>”;

echo “</product>”;

Now in the flex app use HTTPService to get the data,like below.

[showmyads]

<mx:HTTPService id=”productlist” url=”product_.php” useProxy=”false” showBusyCursor=”true” />

Now in the datagrid control use the dataprovider property to mention the httpservice id and in the datagridcolumn use the property datafield to the required field in to the column.

<mx:DataGrid x=”10″ y=”39″ height=”200″ id=”datagrid” dataProvider=”{productlist.lastResult.product.items}” >
<mx:columns>
<mx:DataGridColumn headerText=”FirstName” dataField=”name1″ visible=”true”/>
<mx:DataGridColumn headerText=”Last Name” dataField=”name2″ visible=”true”/>
</mx:columns>
</mx:DataGrid>

Advertisements

6 Responses to Read Data from Database into DataGrid Control: PHP backend

  1. thanks for this 🙂

  2. sakthipsm says:

    thanks for this

  3. crusader says:

    please explain the content of dataprovider what is lastResult doing. Thank you .

  4. jindal says:

    works for me

  5. the-1-e says:

    m doing the same thing but getting error can someone help…the follwing is the error i get…

    VerifyError: Error #1014: Class IWatcherSetupUtil could not be found.

    at flash.display::MovieClip/nextFrame()
    at mx.core::FlexModuleFactory/deferredNextFrame()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:467]
    at mx.core::FlexModuleFactory/update()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:295]
    at mx.core::FlexModuleFactory/moduleCompleteHandler()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:542]

    when i click on continue i get this…

    ReferenceError: Error #1065: Variable _DataGridStyle__embed_css_Assets_swf_cursorStretch_187066769 is not defined.

    at flash.display::MovieClip/nextFrame()
    at mx.core::FlexModuleFactory/deferredNextFrame()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:467]
    at mx.core::FlexModuleFactory/update()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:295]
    at mx.core::FlexModuleFactory/moduleCompleteHandler()[C:autobuild3.2.0frameworksprojectsframeworksrcmxcoreFlexModuleFactory.as:542]

    later on no module is loaded. if i remove the code to get that data and dataprovider in grid than it displays the empty grid

  6. Christian says:

    wow, this is great. thanks for the info.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: