|
 |
|
ตอนนี้เขียน php ให้แสดงเป็น xml ได้แล้วคะ แต่อยากให้มัน output ออกมาเป็นไฟล์ xml ด้วยจะเขียนอย่างไรดีค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
require("phpsqlajax_dbinfo.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM imagesss";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<Content>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<Item>';
echo '<Image>';
echo '' . parseToXML($row['img_path']) . '';
echo '</Image>';
echo '<Thumb>';
echo 'name="' . parseToXML($row['name']) . '" ';
echo '</Thumb>';
echo '<Title>';
echo 'name="' . parseToXML($row['name']) . '" ';
echo '</Title>';
echo '<Caption>';
echo '<![CDATA[ ]]>';
echo '</Caption>';
echo '<Media>';
echo '<![CDATA[ ]]>';
echo '</Media>';
echo '<LightboxMedia>';
echo '<![CDATA[ ]]>';
echo '</LightboxMedia>';
echo '<Link>';
echo 'name="' . parseToXML($row['name']) . '" ';
echo '</Link>';
echo '<Target>';
echo '_blank';
echo '</Target>';
echo '</Item>';
}
// End XML file
echo '</Content>';
?>
อันนี้โค๊ด php ค่ะ ส่วนโค๊ดอันล่างนี้เป็นคำสั่ง output ไฟล์ xml คะ จะเอามาใช้ร่วมกับโค๊ดหนูยังไงค่ะ
Code (PHP)
//export xml file
$xml->asXML("devplaylist.xml");
Tag : PHP, MySQL, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2012-08-04 12:13:00 |
By :
dferru |
View :
1329 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|