I have made the following code to take information from a MySQL
database to an XML format so that I can display the data in a table. I
know I can do this without using XML and I have been able to, but
people here want the output in XML format.
I am using an XSLT stylesheet to display the data and when I try to
look at the data it just shows the data in a single line. If I cut and
paste the source code that is produced in a text file and name it
filename.xml and load that it shows the table perfectly. What am I
doing wrong that it won't parse the output from PHP as XML and run it
through my stylesheet. Thanks
here is my code:
<?php include "mysql_connect2.php";
mysql_select_db('chemdata') or exit(mysql_error());
$query = 'SELECT * FROM alumni_data';
$resultID = mysql_query($query, $connection) or die("Data not found.");
//Start the xml output
$xml_output = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
$xml_output .= "<?xml-stylesheet type=\"text/xsl\"
href=\"alumni_table.xslt\"?>\n";
$xml_output .= "<alumni>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
//If statement to change rsvp from boolean to a yes or no
if ($row['rsvp'] == "1") {
$attend = "Yes";
} else {
$attend = "No";
}
//Start the XML Hierarchy
$xml_output .= "\t<alumnus>\n";
$xml_output .= "\t\t<firstname>" . $row['firstname'] .
"</firstname>\n";
$xml_output .= "\t\t<lastname>" . $row['lastname'] .
"</lastname>\n";
$xml_output .= "\t\t<mi>" . $row['mi'] . "</mi>\n";
$xml_output .= "\t\t<advisor>" . $row['advisor'] . "</advisor>\n";
$xml_output .= "\t\t<degree>" . $row['degree'] . "</degree>\n";
$xml_output .= "\t\t<email>" . $row['email'] . "</email>\n";
$xml_output .= "\t\t<attend>" . $attend . "</attend>\n";
$xml_output .= "\t</alumnus>\n";
}
$xml_output .= "</alumni>\n";
print $xml_output;
?>