Hi,

Untested but it would be something like this:


<?php
header("Content-Type: application/xml");
 
//query database records
$connection = mysql_connect("localhost", "user", "pass") or die("can't connect");
mysql_select_db("webbish");
$query = "SELECT id, title, artist FROM xmldb";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0){
        //Create DomDocument
        ob_start();
        echo '<?xml version="1.0" encoding="iso-8859-1"?><cds/>';
        $buffer = ob_get_contents();
        ob_end_clean();
        $doc = domxml_open_mem($buffer);
        //Get root node
        $root = $doc->document_element();
         //Iterate through result set
        while(list($id, $title, $artist) = mysql_fetch_row($result)){
          //create item node
          $record = $root->new_child("cd", "");
          $record->set_attribute("id", $id);
          //Attach title and artist as children of item node
          $record->new_child("title", $title);
          $record->new_child("artist", $artist);
        }
         echo $doc->dumpmem();
} 
?>




-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to