PHP Converts mysql database data into XML
Moderator: General Moderators
PHP Converts mysql database data into XML
Ok here is what i've got....i have a php script that selects data from a mysql database and then converts it into xml ...the script runs in a infinate loop.....problem is when i test the page i get an error that says "Only one top level element is allowed in an XML document. ".........i know the problem is that i'm running a loop......(top level element is being created over and over again ).......but i need it to run in a loop so that when new data is added to the database the php script automatically converts it into xml........what do you guys think i should do to resolve my issue? 
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Everah | Please use
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Well It wasn't a script problem.........it was a internet explorer problem............i ran the code in firefox and it worked perfectly...........Internet explorer 7 better be better microsoft * shakes fist * here is the code if anybody intrestedCode: Select all
<?php
//this loop works well at a command prompt but a browser won't display it because the parent element "products" is only allowed once.
while(1) {
$link = mysql_connect("localhost","root","KKT1KKT1");
mysql_select_db("brimelow_store");
$query = 'select * from products';
$results = mysql_query($query);
echo"<?xml version=\"1.0\"?>\n";
echo"<products>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["products"] . "</item>\n";
}
echo"</products>\n";
mysql_close($link);
}
?>Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
What's with the
Code: Select all
while (1) {- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
here is the flash if anybody intrested there is a list object on the stage with a instance name of theList
Code: Select all
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function (){
var nodes = this.firstChild.childNodes;
for (i=0;i<nodes.length;i++){
theList.addItem(nodes[i].firstChild.nodeValue),i
}
}
theXML.load("http://localhost/webserver1/development/products2.php")- christian_phpbeginner
- Forum Contributor
- Posts: 136
- Joined: Sat Jun 03, 2006 2:43 pm
- Location: Java
Hi everybody, I don't know if it's worth to use the xml_writer built-in function in PHP than to create one by ourself like calmches did. Anybody has tried using the built-in function to write XML ??
http://id.php.net/manual/en/ref.xmlwriter.php
Thanks!
http://id.php.net/manual/en/ref.xmlwriter.php
Thanks!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA