Hi I’m new here and I’m trying to learn flex programming and flash builder. I still have a lot to learn to be honest. I am practically teaching myself to learn this.
Here is my problem. I am trying to display data from my database that I “converted/passed” to xml and display it in a grid view.
Here is my sql statements in php
<?php
$username = "root";
$password = "";
$database = "testdrive_db";
$SQL_query = "SELECT * FROM employees";
$DB_link = mysql_connect(localhost, $username, $password, $database) or die("Could not connect to host.");
mysql_select_db($database, $DB_link) or die ("Could not find or access the database.");
$result = mysql_query ($SQL_query, $DB_link) or die ("Data not found. Your SQL query didn't work... ");
$strXmlData = "<employees>";
while ($row = mysql_fetch_array($result)) {
$strXmlData .= '<employee no="'.$row{"id"}.'" firstname="'.$row{"fname"}.'" City="'.$row{"city"}.'" Title="'.$row{"title"}.'" Email="'.$row{"email"}. '"/>';
}
$strXmlData .= "</employees>";
echo $strXmlData;
?>
I know the above code works because I am able to view the xml format when I click “view source” when I launch it in my localhost.
Here is my code in flash builder:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
protected function creationCompleteHandler(event:FlexEvent):void
{
var httpReq:HTTPService = new HTTPService();
httpReq.url = "http://localhost/myfirstphp/testconnection.php";
httpReq.resultFormat = "e4x";
var objParams:Object = new Object();
objParams.name = "myname";
var myToken:AsyncToken = httpReq.send(objParams);
var rsponder:mx.rpc.Responder = new mx.rpc.Responder(fncSuccess, fncStatus);
myToken.addResponder(rsponder);
}
private function fncSuccess(evnt:ResultEvent):void
{
// TODO Auto Generated method stub
trace(evnt.result);
var myArrCol:ArrayCollection = new ArrayCollection
var xml:XML = XML(evnt.result);
for each(var item:Object in xml.employee)
{
var myObj:Object = new Object();
myObj.id = item.@no;
myObj.fname = item.@firstname;
myObj.city = item.@City;
myObj.title = item.@Title;
myObj.email = item.@Email;
myArrCol.addItem(myObj);
}
dg.dataProvider = myArrCol;
}
private function fncStatus(evnt:ResultEvent):void
{
// TODO Auto Generated method stub
trace(evnt.result);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Form width="500">
<s:DataGrid id="dg" width="100%" height="100%">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="id" headerText="Id"/>
<s:GridColumn dataField="fname" headerText="First Name"/>
<s:GridColumn dataField="city" headerText="City"/>
<s:GridColumn dataField="title" headerText="Title"/>
<s:GridColumn dataField="email" headerText="Email"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:FormItem label = "ID No:">
<s:TextInput text="{dg.selectedItem.id}"/>
</s:FormItem>
<s:FormItem label="Name:">
<s:TextInput text="{dg.selectedItem.fname}"/>
</s:FormItem>
<s:FormItem label="City:">
<s:TextInput text="{dg.selectedItem.city}"/>
</s:FormItem>
<s:FormItem label="email:">
<s:TextInput text="{dg.selectedItem.email}"/>
</s:FormItem>
<s:FormItem>
<s:Button label="Edit"/>
</s:FormItem>
</s:Form>
</s:Application>
What happens is that I am able to display the “id number” and the “first name” but the city and email or any other data from my table are blank in my grid view. I really don’t know what is wrong.
I will be very grateful for your help.