我正在尝试将 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
?>