Forum Moderators: open
Trying to create xml from php, however the whole xsl part have me stuck.
The following is my php:
Note: This is my first attempt with this so please go easy on me.
<?
header ("content-type: text/xml");
echo "<?xml version='1.0' standalone='yes'?>\n\n";
echo "<query_result>\n";
echo "<title>Browse records for the nuke_pc_item table</title>\n";$db = "athcast_nuke1";
$table = "nuke_pc_item";
$conn = mysql_connect("localhost") or die ("Could not connect");
mysql_select_db ($db, $conn) or die ("Could not select database $db");
$query = "SELECT * from nuke_pc_item";
$resultHandle = mysql_query( $query, $conn ) or die ("Could not run query");
$numRows = mysql_num_rows ($resultHandle);
echo "<db_queried>$db</db_queried>\n";
echo "<query>$query</query>\n";
echo "<result_size>$numRows</result_size>\n";
echo "<table>\n";
echo "<table_header>\n";
echo "<column_header>pc_i_id</column_header>\n";
echo "<column_header>pc_i_title</column_header>\n";
echo "<column_header>pc_i_sub</column_header>\n";
echo "</table_header>\n";
$i = 0;
while ($i < $numRows) {
echo "<table_row>\n";
$row = mysql_fetch_row ($resultHandle);
echo "<table_element>$row[pc_i_id]</table_element>\n";
echo "<table_element>$row[pc_i_title]</table_element>\n";
echo "<table_element>$row[pc_i_auth]</table_element>\n";
echo "</table_row>\n";
$i++;
}
echo "</table>\n";
echo "</query_result>\n";
mysql_close($conn);
?>
This is the error Im getting:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
The following tags were not closed: query_result. Error processing resource
I know I need to somehow transform my data and also use a xsl ... but how to go about all of that is where I am stuck.
I would be thankful for any direction you guys may have for me.
Try replacing
<?xml version='1.0' standalone='yes'?>
with this. (and replace simple.xsl with your stylesheet)
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
by doing that, you will create an xml document that will be transformed by a browser when rendered.