Listing MySQL Database Table Using PHP, XML and DataGrid Component

This is an example of using Flash XML class to request records in a MySQL table via PHP. All the scripting and database commands are listed below. All the ActionScript is on frame 1 of the XMLPHPMySQLEx01_Request Flash movie plus a DataGrid component named myUserDataGrid and a TextField named output_txt that displays output for testing outside the Flash IDE.

XMLPHPMySQLEchoEx01_Request Actionscript Frame 1
/*----------------------------------------------------------------------
	Copyright:			2005 Lon Hosford: http://www.lonhosford.com
						Permission to use in your own applications
						but not to use for publication electronically
						or otherwise without written permission.

	Purpose:			Initialization of variables and functions
						for the movie.

	Version history:
		Number:			1.00.00
		Date:			9/15/2005
		File name:		XMLPHPMySQLEx01.fla
		Object:			
		Time line:		_root
		Frame:			1
		Programmer:		Lon Hosford: http://www.lonhosford.com
		Changes:		Original programming
----------------------------------------------------------------------
	Initialize output window for tracing Actionscript from published
	movie

----------------------------------------------------------------------*/
output_txt.background = true
output_txt.backgroundColor = 0xffffff
output_txt.html = true
output_txt.htmlText = "Frame 1
"

/*----------------------------------------------------------------------
	 Create xmlData_xml XML instance
----------------------------------------------------------------------*/
xmlData_xml = new XML();
/*----------------------------------------------------------------------
	 Text nodes that contain only white space are discarded during
	 the parsing process. Text nodes with leading or trailing 
	 white space are unaffected.
----------------------------------------------------------------------*/
xmlData_xml.ignoreWhite = true;

/*----------------------------------------------------------------------
	 The onLoad method for xmlData_xml XML instance.
----------------------------------------------------------------------*/
xmlData_xml.onLoad = function( success ) {
	output_txt.htmlText += "xmlData_xml.onLoad"
	/*----------------------------------------------------------------------
		Uncomment for displaying xmlData_xml XML instance members
	----------------------------------------------------------------------*/
	//for (key in xmlData_xml)
	//{
		//trace(key + " - " + xmlData_xml[key])
	//}
	/*----------------------------------------------------------------------
		Successful response received from server
	----------------------------------------------------------------------*/
	if ( success ) {
		output_txt.htmlText += "Load succeeded"
		output_txt.htmlText += "<" + this.xmlDecl.split("<")[1].split(">")[0] + ">"
		/*----------------------------------------------------------------------
			The datapacket node
		----------------------------------------------------------------------*/
		output_txt.htmlText += xmlData_xml.firstChild.nodeName 
			/*----------------------------------------------------------------------
				The response node
			----------------------------------------------------------------------*/
			output_txt.htmlText += "---" + xmlData_xml.firstChild.childNodes[0].nodeName
				/*----------------------------------------------------------------------
					The stats node
				----------------------------------------------------------------------*/
				output_txt.htmlText += "------" + xmlData_xml.firstChild.childNodes[0].childNodes[0].nodeName 
				/*----------------------------------------------------------------------
					Each stats node attributes
				----------------------------------------------------------------------*/
				for (key in  xmlData_xml.firstChild.childNodes[0].childNodes[0].attributes)
				{
					output_txt.htmlText += "---------" + key + " - " + xmlData_xml.firstChild.childNodes[0].childNodes[0].attributes[key]

				}
				/*----------------------------------------------------------------------
					The code node
				----------------------------------------------------------------------*/
				output_txt.htmlText += "---" + xmlData_xml.firstChild.childNodes[0].childNodes[1].nodeName 
				// value for code
				output_txt.htmlText += "------" + xmlData_xml.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue
				/*----------------------------------------------------------------------
					The message node
				----------------------------------------------------------------------*/
				output_txt.htmlText += "---" + xmlData_xml.firstChild.childNodes[0].childNodes[2].nodeName 
				// value for message
				output_txt.htmlText += "------" + xmlData_xml.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue
			/*----------------------------------------------------------------------
				The users node
			----------------------------------------------------------------------*/
			output_txt.htmlText += "---" + xmlData_xml.firstChild.childNodes[1].nodeName
			/*----------------------------------------------------------------------
				Each user node
			----------------------------------------------------------------------*/
			// each user node in users node
			for (userI = 0; userI < xmlData_xml.firstChild.childNodes[1].childNodes.length; userI++)
			{
				/*----------------------------------------------------------------------
					Each node in user node
				----------------------------------------------------------------------*/
				for (userFieldsI = 0; userFieldsI < xmlData_xml.firstChild.childNodes[1].childNodes[userI].childNodes.length; userFieldsI++)
				{
					/*----------------------------------------------------------------------
						Add node name and value to myUserDataGrid DataGrid component instance
					----------------------------------------------------------------------*/
					myUserDataGrid.addItem(
						{ 	Node	:
							xmlData_xml.firstChild.childNodes[1].childNodes[userI].childNodes[userFieldsI].nodeName ,
							Value	: 
							xmlData_xml.firstChild.childNodes[1].childNodes[userI].childNodes[userFieldsI].firstChild.nodeValue
						})
					
					output_txt.htmlText += "------" + xmlData_xml.firstChild.childNodes[1].childNodes[userI].childNodes[userFieldsI].nodeName 
					output_txt.htmlText += "---------" + xmlData_xml.firstChild.childNodes[1].childNodes[userI].childNodes[userFieldsI].firstChild.nodeValue
				}
				/*----------------------------------------------------------------------
					Add blank row to myUserDataGrid DataGrid component instance
				----------------------------------------------------------------------*/
				myUserDataGrid.addItem(
						{ 	Node	:
							"",
							Value	: 
							""
						})
					
			}
	/*----------------------------------------------------------------------
		No response received from server
	----------------------------------------------------------------------*/
	} else {
		output_txt.htmlText += "Load Failed"
		
	}
	/*----------------------------------------------------------------------
		Show output_txt.text in output window
	----------------------------------------------------------------------*/
	trace(output_txt.text)
 }

/*----------------------------------------------------------------------
	 Testing on http request where XMLPHPMySQLEx01_Response.php
	 is in same folder
----------------------------------------------------------------------*/
xmlData_xml.load("XMLPHPMySQLEx01_Response.php");
/*----------------------------------------------------------------------
	 Testing on in Flash IDE
	 Provide appropriate http:// reference to 
	 XMLPHPMySQLEx01_Response.php
----------------------------------------------------------------------*/
//xmlData_xml.load("http://www.yoursite.com/path-to-XMLPHPMySQLEx01_Response.php/XMLPHPMySQLEx01_Response.php");