Free sample code HTTP Service with PHP
This sample using Datagrid and HTTP Service. HTTP Service getting data from database with PHP.
Flex Code :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="getListDataBrg.send()">
<mx:HTTPService id="getListDataBrg" method="POST" showBusyCursor="true" useProxy="false" url="http://localhost/kunci/srv/databrg.php"/>
<mx:DataGrid x="312" y="57" dataProvider="{getListDataBrg.lastResult.data.detail}">
<mx:columns>
<mx:DataGridColumn headerText="Item Code" dataField="kode" width="130"/>
<mx:DataGridColumn headerText="Item Name" dataField="nama"/>
<mx:DataGridColumn headerText="Item Unit" dataField="unit"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
PHP code > databrg.php
<?
header('Content-Type: text/xml');
include('adodb/adodb.inc.php'); # load code common to ADOdb
$connectX = ADONewConnection('mssql'); # create a connection
$connectX -> Connect("yodi-it","USERNAME","PASSWORD",'DATABASENAME');
$databrg = $connectX->Execute("SELECT KDBRG,NMBRG,UNIT FROM TABLE_NAME");
$xml="<data>";
$xml.="<count>".$databrg->RecordCount()."</count>";
while(!$databrg->EOF)
{
$xml.="<detail>";
$xml.="<kode>".trim($databrg->fields[0])."</kode>";
$xml.="<nama>".trim(str_replace('&','&',$databrg->fields[1]))."</nama>";
$xml.="<unit>".trim($databrg->fields[2])."</unit>";
$xml.="</detail>";
$databrg->MoveNext();
}
$xml.="</data>";
print($xml);
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment