PDA

View Full Version : Problem loading data from mySQL to datagrid


estudio56
10-03-2008, 02:54 AM
Hi,

I have a mxml file, a php file and a mysql database.

. the mxml file has a simple datagrid, binded to the httpservice request.
. the php file retrieves data from a mysql database and returns it in XML format to the mxml file.

When executed, for some reason the datagrid doesn't display the data properly. If you rollover the datagrid, you can actually see the rows are there, but text doesn't show.

The project can be found in http://www.imfo.com/flex/conferences.swf

The php file can be found in http://www.imfo.com/flex/list.php

Any ideas? First time it happens, and I have done datagrid binding before.

drkstr
10-03-2008, 04:15 AM
Show your code.

estudio56
10-03-2008, 05:10 AM
Show your code.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="openLoginPopUp()" verticalAlign="top" horizontalAlign="center" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#F4F7FF, #6DAEFF]">

<mx:HTTPService id="conferenceList" useProxy="false" showBusyCursor="true" />
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.managers.PopUpManager;

public var baseURL:String = "http://www.imfo.com/flex/list.php";
public function openLoginPopUp() : void {

listItems();
}
private function listItems():void {
conferenceList.url=baseURL+"?do=list";
conferenceList.send();
}
]]>
</mx:Script>

<mx:ApplicationControlBar width="500" fillAlphas="[1.0, 1.0]" fillColors="[#021183, #4E63FF]">
<mx:Button label="Add new conference" borderColor="#FFFFFF" fillAlphas="[1.0, 1.0]" fillColors="[#E9E9E9, #FFFFFF]" />
<mx:Button label="Delete" borderColor="#FFFFFF" fillAlphas="[1.0, 1.0]" fillColors="[#E9E9E9, #FFFFFF]"/>
</mx:ApplicationControlBar>
<mx:DataGrid width="100%" height="100%" id="dataList" doubleClickEnabled="true" dragEnabled="false" wordWrap="true" themeColor="#FFB400" dataProvider="{conferenceList.lastResult.conferences.item}" draggableColumns="false">
<mx:columns>
<mx:DataGridColumn headerText="Event" dataField="eventID" />
<mx:DataGridColumn headerText="Date FROM" dataField="datefromID" />
<mx:DataGridColumn headerText="Date TO" dataField="datetoID" />
<mx:DataGridColumn headerText="Description" dataField="descriptionID" />
<mx:DataGridColumn headerText="Website" dataField="websiteID" />
</mx:columns>
</mx:DataGrid>
</mx:Application>

estudio56
10-03-2008, 05:43 AM
And my PHP code...

<?php

$action = $_GET['do'];

$myServer = "www.xxx.com";
$myUser = "xxx";
$myPass = "xxx";
$myDB = "xxx";

$dbhandle = mysql_connect($myServer, $myUser, $myPass) or die( mysql_error() );

$selected = mysql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");

function getConferences() {

$sql = "SELECT * FROM conferences ORDER BY event ASC;";
$record = mysql_query($sql);

$s="<conferences>";
while($row = mysql_fetch_assoc($record)){
$s.= "<item>";
$s.= "<id>".$row['id_conferences']."</id>";
$s.= "<event>".$row['event']."</event>";
$s.= "<datefrom>".$row['date_from']."</datefrom>";
$s.= "<dateto>".$row['date_to']."</dateto>";
$s.= "<description>".$row['description']."</description>";
$s.= "<website>".$row['website']."</website>";
$s.= "</item>";
}

$s.="</conferences>";

return $s;
}

if ($action == "list"){
print getConferences();
}

?>

estudio56
10-03-2008, 03:42 PM
Guys.... any pointers?:confused:

Peter Cowling
10-03-2008, 05:07 PM
Is the php script working properly: are you receiving the data back, and is it formed as you would expect?

If you are not sure, I would take a look through Charles. http://www.charlesproxy.com/index.php

estudio56
10-03-2008, 05:46 PM
Peter, if you follow through this link, you can actually see php is printing the XML string properly.

http://www.imfo.com/flex/list.php?do=list

Funny thing is, it seems that php is communicating with flex properly. On the datagrid, I even get the rollover effect when I walk my mouse over the table. Like, it seems to have as many rows as returned by the php, but text is not showing.

It's hard to explain, hope I made myself clear...

estudio56
10-03-2008, 05:50 PM
Peter, if you follow through this link, you can actually see php is printing the XML string properly.

http://www.imfo.com/flex/list.php?do=list

Funny thing is, it seems that php is communicating with flex properly. On the datagrid, I even get the rollover effect when I walk my mouse over the table. Like, it seems to have as many rows as returned by the php, but text is not showing.

It's hard to explain, hope I made myself clear...

I just realized this rollover effect I'm referring to only shows client side. For some reason it doesn't show server side. Just to clarify.

drkstr
10-04-2008, 02:56 AM
If you look at your XML, you have nodes filled with html tags which changes the structure of the xml.

You might want to try something like this:

$s.= "<description><![CDATA[".$row['description']."]]></description>";


Best Regards,
~Aaron

estudio56
10-04-2008, 04:58 AM
Well, it's HTML once it's actually parsed on an HTML page. In the meantime, Flex's datagrid and mySql database just understands it as a string.

Still, I have tried your suggestion and it didn't work. I even tried setting resultFormat to xml, e4x and object. And still shows blank. :o

drkstr
10-04-2008, 06:23 AM
Well, it's HTML once it's actually parsed on an HTML page.Actually it's HTML no matter where it's at. And to be more exact, it's actually XML which gets turned into HTML when you apply a style to it. The problem with this is that it get interpreted as an XML Object and not a String.

You will see why this is a problem after you name your data fields correctly.

<mx:DataGrid width="100%" height="100%" id="dataList" doubleClickEnabled="true" dragEnabled="false" wordWrap="true" themeColor="#FFB400" dataProvider="{conferenceList.lastResult.conferences.item}" draggableColumns="false">
<mx:columns>
<mx:DataGridColumn headerText="Event" dataField="datefrom" />
<mx:DataGridColumn headerText="Date FROM" dataField="datefrom" />
<mx:DataGridColumn headerText="Date TO" dataField="dateto" />
<mx:DataGridColumn headerText="Description" dataField="description" />
<mx:DataGridColumn headerText="Website" dataField="website" />
</mx:columns>
</mx:DataGrid>

Using CDATA will help you parse the data as a string of html text and not as XML when you use it in your itemRenderer.


Best Regards,
~Aaron

estudio56
10-04-2008, 06:07 PM
I'd like to thank u guys, problem has been solved.

Both things were necessary. The CDATA wrapped around the html code in my XML and the fact that I named every dataField with an "ID" postfix. I didn't know it was gonna clash with Flex's reserved variables.

So thanks for your input, much appreciated!

C u around,

Sebastian.:)

drkstr
10-05-2008, 02:37 AM
I didn't know it was gonna clash with Flex's reserved variables.There wasn't any clash between reserved variables. You have to name the data fields the same as in your XML. It's like an object. You can't say obj.heightID = 5 when the property is height.


Best Regards,
~Aaron

estudio56
10-05-2008, 09:01 AM
Now I gotcha, thanks.