从请求的数据填充datagridview

时间:2013-04-25 23:43:43

标签: php xml actionscript-3 actionscript air

我正在尝试将XML文档加载到Actionscript中的DataGridView中。但我正在从mysql结果创建php中的xml。所以我需要发送我的php用户名来从mysql数据库中选择正确的记录并将它们显示在xml文档中。

function showresults(e:Event):void
{

var formVars:URLVariables = new URLVariables();
var variableRequest:URLRequest = new URLRequest("php link");
variableRequest.method = URLRequestMethod.POST;
variableRequest.data = formVars;
var varLoader:URLLoader = new URLLoader();
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

formVars.UserName = USERNAME;


varLoader.addEventListener(Event.COMPLETE, loadresults);



varLoader.load(variableRequest);
stage.removeEventListener(Event.ENTER_FRAME, loadresults);


XML.ignoreWhitespace = true;

}
function loadresults(e:Event):void
{
xmlData = new XML(e.target.data);
var dp:DataProvider = new DataProvider(xmlData);

var col1:DataGridColumn = new DataGridColumn("title");
col1.headerText = "Exam titile";
col1.width = 200;
var col2:DataGridColumn = new DataGridColumn("score");
col2.headerText = "Score";
col2.width = 200;

dgv.columns = [col1,col2];
dgv.width = 400;
dgv.dataProvider = dp;
dgv.rowCount = dgv.length;


}

这是加载datagridview bu没有输出信息。 php代码是:

$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";

$UNAME = $_POST ['UserName'];
// Connect to your MySQL database whatever way you like to here
mysql_connect(database information) or die (mysql_error());
mysql_select_db("table) or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM FYP_RESULT WHERE USERNAME = '$USER'");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use 
$title = $row["EXAM_TITLE"]; 
$score = $row["EXAM_SCORE"];  


$xmlBody .= '
<Data> 
<title>' . $title . '</title> 
<score>' . $score . '</score>
</Data>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>

0 个答案:

没有答案