jammydevil Posted January 15, 2007 Share Posted January 15, 2007 Hello,I have a news PHP script using data from a MySQL database. I've used the below PHP script to extract the most recent three entries and create an XML file. This is then used by JavaScript to display the data in a rotating news display, similar to that found at [url=http://www.mlsnet.com]http://www.mlsnet.com[/url].[code]include('news/flash/admin/functions.php');connect('username','password','hurri_news','localhost');$query = "SELECT newsid, image, title, home, DATE_FORMAT(date, '%M %d, %Y') as date FROM news_posts ORDER BY newsid DESC LIMIT 3"; $result = mysql_query($query);// create a new XML document$doc = new DomDocument('1.0');// create root node$root = $doc->createElement('root');$root = $doc->appendChild($root);// process one row at a timewhile($row = mysql_fetch_array($result)) { // add node for each row $occ = $doc->createElement("news"); $occ = $root->appendChild($occ); // add a child node for each field $child = $doc->createAttribute("id"); $child = $occ->appendChild($child); $value = $doc->createTextNode(stripslashes2($row['newsid'])); $value = $child->appendChild($value); $child = $doc->createAttribute("img"); $child = $occ->appendChild($child); $value = $doc->createTextNode(stripslashes2($row['image'])); $value = $child->appendChild($value); $child = $doc->createAttribute("title"); $child = $occ->appendChild($child); $value = $doc->createTextNode(stripslashes2($row['title'])); $value = $child->appendChild($value); $child = $doc->createAttribute("body"); $child = $occ->appendChild($child); $value = $doc->createTextNode(stripslashes2($row['home'])); $value = $child->appendChild($value);} // while// get completed xml document$xml_string = $doc->saveXML();echo $xml_string;[/code]I have managed to create the XML file and the script works perfectly in Internet Explorer 7 but does not work at all in Firefox. When I view the source in Firefox the data is displayed properly but JavaScript can't seem to use the data correctly. The JavaScript works fine when using a static XML file in both browsers but that would defeat the purpose of using the database. Can anybody advise me the best way to approach this problem or why Firefox would have trouble displaying this data? If this is the wrong forum I apologise.Thanks,Jay Quote Link to comment Share on other sites More sharing options...
fenway Posted January 15, 2007 Share Posted January 15, 2007 If it's a browser issue, it's not MySQL's fault, but with the PHP output.... moving to the appropriate forum. Quote Link to comment Share on other sites More sharing options...
jammydevil Posted January 16, 2007 Author Share Posted January 16, 2007 Never mind, I've fixed the problem. For anybody wanting to know, I hadn't set the headers correctly. I needed to add[code]header("Content-Type: text/xml");[/code] after the DomDocument is created. This allows Firefox to read the file as an XML file where as Internet Explorer isn't as picky. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.