XML with mySQL and DOM

homeskooled

New Member
How can I get the code below to output node names that I define? As of now, it creates the nodes based on column names of an SQL table. I want to define both the columns and the nodes. Also, how can I code it so that when someone inserts data into my table it appends that data to the inserted data? E.g.: \[code\]Input data: "davidjmorin"Data inserted: "http://someurl.com/davidjmorin"\[/code\]Here is my code for the original question:\[code\]<?//header('Content-type: text/xml');$link = mysql_connect('localhost','root','IhaveAlLthEanSwers2012!');mysql_select_db('bb_links');$sql = "Select * from `links`";$run = mysql_query($sql, $link);if( $run && mysql_num_rows( $run ) ) {$doc = new DOMDocument( '1.0' );$doc->formatOutput = true;$doc->preserveWhiteSpace = true;$root = $doc->createElement( 'data' );$doc->appendChild( $root );while( ( $fetch = mysql_fetch_assoc( $run ) )!== false ) { $node = $doc->createElement( 'channel' ); $root->appendChild( $node ); foreach( $fetch as $key => $value ) { createNodes( $key, $value, $doc, $node ); }}$doc->save("thelinks.xml");}//$node = "channel";function createNodes( $key, $value, $doc, $node ) {$key = $doc->createElement( $key );$node->appendChild( $key );$key->appendChild( $doc->createTextNode( $value ) );}?>\[/code\]
 
Back
Top