Hi,
I have a php.php file which fetches data from a mysql table and displays the results in XML but within the php.php page
I would like to results to be outputed to an XML file instead... is this possible? I currently have the results in variable $xml_output and then echoing it on the page.. this works fine so far, but need the results in an XML file. Here's what i have so far:
<?php
header("Content-type: text/xml");
$host = "localhost";
$user = "test";
$pass = "test";
$database = "education";
$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 blog ORDER BY title DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<title>" . $row['title'] . "</title>\n";
// Escaping illegal characters
$row['objective'] = str_replace("&", "&", $row['objective']);
$row['objective'] = str_replace("<", "<", $row['objective']);
$row['objective'] = str_replace(">", ">", $row['objective']);
$row['objective'] = str_replace("\"", """, $row['objective']);
$xml_output .= "\t\t<objective>" . $row['objective'] . "</objective>\n";
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
Any help is appreciated.
dR
I have a php.php file which fetches data from a mysql table and displays the results in XML but within the php.php page
I would like to results to be outputed to an XML file instead... is this possible? I currently have the results in variable $xml_output and then echoing it on the page.. this works fine so far, but need the results in an XML file. Here's what i have so far:
<?php
header("Content-type: text/xml");
$host = "localhost";
$user = "test";
$pass = "test";
$database = "education";
$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 blog ORDER BY title DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<title>" . $row['title'] . "</title>\n";
// Escaping illegal characters
$row['objective'] = str_replace("&", "&", $row['objective']);
$row['objective'] = str_replace("<", "<", $row['objective']);
$row['objective'] = str_replace(">", ">", $row['objective']);
$row['objective'] = str_replace("\"", """, $row['objective']);
$xml_output .= "\t\t<objective>" . $row['objective'] . "</objective>\n";
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
Any help is appreciated.
dR