<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ http://www.developphp.com - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("admin") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$news_id = $row["news_id"];
$subject = $row["subject"];
$news_date = strftime("%b %d, %Y", strtotime($row["news_date"]));
$news_artical = $row["news_artical"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>' . $news_id . '</title>
<artist>' . $subject . '</artist>
<country>' . $news_date . '</country>
<company>' . $description . '</company>
</cd>
</catalog>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; // output the gallery data as XML file for flash
?>
ok the problem i'm having is that xml doesnt pick up the style sheet so am thinking either i have set it up the code to pick up the style sheet wrong can anyone see if thats the first case scenario you can see how is current display herebut i want to display using style sheet another thing is i dnt know if maybe i set up the stylesheet wrong desperate help please thanks in advance
<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ http://www.developphp.com - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<catalog>";
$xmlBody .= '<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>';
?>
$xmlBody .= "
<?php
// Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("admin") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql = mysql_query("SELECT * FROM news ORDER BY news_date DESC LIMIT 0, 20");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$news_id = $row["news_id"];
$subject = $row["subject"];
$news_date = strftime("%b %d, %Y", strtotime($row["news_date"]));
$news_artical = $row["news_artical"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= '
<cd>
<title>' . $news_id . '</title>
<artist>' . $subject . '</artist>
<country>' . $news_date . '</country>
<company>' . $description . '</company>
</cd>';
} // End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</catalog>";
echo $xmlBody; // output the gallery data as XML file for flash
?>
no it wasnt cz i couldnt figure out what was wrong with it so i followed another tutorial on another script which once again no luck with it. the problem with this one is that i cant seem to be able to insert the link to stylesheet it keeps given me error when i try to insert this line
$xml_output = "<?xml-stylesheet type="text/xsl" href="class.xsl"?>\n";
buts the version line works fine
lisa007 wrote:no it wasnt cz i couldnt figure out what was wrong with it so i followed another tutorial on another script which once again no luck with it.
Mixing scripts can be a bad way to try to get a script to work because the 2 scripts may approach the task differently and conflict with each other, unless you are really an experienced programmer. I am dodging your question because I don't use XML, so I was just reacting to the error message you presented, which was about the incomplete line I referred to.
Is your XML stylesheet named "class.xsl" and is it in the same directory as the script? That's the first thing to check. But if you're getting error messages, you have to fix those problems first.