我試圖從我的數據庫輸出各種表,但我似乎無法弄清楚如何執行我想到的。Mysql到Xml輸出在頁面
我想輸出像這樣的數據。
<locations>
<destination>
<name>A</name>
<address>B</name>
</destination>
<destination>
<name>C</name>
<address>D</name>
</destination>
</locations>
到目前爲止,我有這個作爲輸出。
<Locations>
<destination name="burlo"/>
<destination name="Raymund"/>
<destination name="Bacolod City"/>
<destination name="Victorias"/>
<destination name="Sipalay"/>
<destination name="Ambot"/>
<destination name="aweawea"/>
<destination name="ilo-ilo"/>
<destination name="ilo-ilo"/>
<destination name="Hinobaan"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="heart"/>
<destination name="Daddy"/>
<destination name="aguisan"/>
</Locations>
這是我如何生成它們。
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("Locations");
$parnode = $dom->appendChild($node);
// Select all the rows in the markers table
$query = "SELECT * FROM tbl_locations where status='active'";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("destination");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name",$row['name']);
}
echo $dom->saveXML();
?>
希望有任何幫助。
http://theintegrity.co.uk/2010/10/generate-xml-from-mysql-in- php/ – 2013-02-23 05:57:04
你的問題是? – hakre 2013-02-28 13:38:17