mysql DOM_使用mySQL和DOM的XML(XML with mySQL and DOM)

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.:

Input data: "davidjmorin"

Data inserted: "http://someurl.com/davidjmorin"

Here is my code for the original question:

//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 ) );

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值