Hi All
I am trying to load data from mysql to xml to flash using actionscript and php. Im doing something wrong but not sure what.
Basically, my php file (latestnews.php) looks like this
<?php
header("Content-type: text/xml");
$host = "host";
$user = "user";
$pass = "password";
$database = "dbname";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM latestnews ORDER BY timestamp DESC LIMIT 0,3";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\" encode=\"UTF-8\"?>
";
$xml_output = "<!DOCTYPE data[
<!ELEMENT headline (text, date)>
<!ATTLIST headline name CDATA #REQUIRED>
<!ELEMENT text (#PCDATA)>
<!ELEMENT date (#PCDATA)>
]>
";
$xml_output .= "<entries>
";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= " <entry>
";
$xml_output .= " <headline name=\" ". $row['headline'] . "\">
";
// Escaping illegal characters
$row['content'] = str_replace("&", "&", $row['content']);
$row['content'] = str_replace("<", "<", $row['content']);
$row['content'] = str_replace(">", ">", $row['content']);
$row['content'] = str_replace("\"", """, $row['content']);
$xml_output .= " <text><![CDATA[" . $row['content'] . "]]></text>
";
$xml_output .= " <date><![CDATA[" . $row['timestamp'] . "]]></date>
";
$xml_output .= " </headline>
";
$xml_output .= " </entry>
";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
this produces the following xml layout
<entries>
−
<entry>
−
<headline name=" This is a Test News">
<text>Test News Description</text>
<date>2009-05-17 19:40:33</date>
</headline>
</entry>
−
<entry>
−
<headline name=" Site launch 21st May 2009">
−
<text>
test news
</text>
<date>2009-05-17 19:38:50</date>
</headline>
</entry>
−
<entry>
−
<headline name=" This is another test news">
<text>Test news news news news</text>
<date>2009-05-17 00:00:00</date>
</headline>
</entry>
</entries>
my actionscript is then as follows
myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("admin/includes/latestnews.php");
myXML.ref = this;
myXML.onLoad = function(success){
if(success){
var root = this.firstChild;
nodes = root.childNodes;
for(var i=0; i<nodes.length; i++) {
this.ref["Title_txt"+i].htmlText = nodes*.attributes.name;
subnodes = nodes*.childNodes;
this.ref["Comments_txt"+i].htmlText = subnodes[0].firstChild.toString();
this.ref["Date_txt"+i].htmlText = subnodes[1].firstChild.toString();
}
} else trace("Error loading XML document");
}
this is placed in the same frame number as the dynamic text fields but on a seperate layer. The dynamic text fields are:
Title_txt
Comments_txt
Date_txt
There is no output error but nothing is showing up. The file is using actionscript 2.0 and wondering if the actionscript i am using is write for that format?
any help would be great, bit of a novice with xml loading!