Saturday, 3 January 2015

Create simple xml file from sql database



I'm a newbee to sql code .I need help to generate a simple xml file of youtube id's from my sql database via php.


DESIRED OUTPUT





<videos>
<youtube media="http://ift.tt/1xEaHMj" autoplay="false">
<![CDATA[<thumbHead>Customizable skin</thumbHead><thumbBody>Images are in the assets/skins folder</thumbBody>]]></youtube>
<youtube media="http://ift.tt/IL8rW4" autoplay="false">
<![CDATA[<thumbHead>Repeat & Shuffle</thumbHead><thumbBody>Functionalities available</thumbBody>]]></youtube>
<youtube media="http://ift.tt/1xEaHMk" autoplay="false">
<![CDATA[<thumbHead>Playlist can be</thumbHead><thumbBody>hidden and revealed with the click of a button</thumbBody>]]></youtube>
</videos>



This is the output I get from a database query


SELECT value FROM jr_jryoutube_item_key WHERE key = "youtube_id"





----------
value
---------
b4_uOngDRRc
pAL2qWVm9uA
89P0I5Qbio8
m96CfaeGhSw
VIV8L8ItDqg



Below is my attempt but it's not generating anything.





<?php
//database configuration
$config['mysql_host'] = "localhost";
$config['mysql_user'] = "xxxxxx";
$config['mysql_pass'] = "xxxxxx";
$config['db_name'] = "xxxxxx";
//connect to host
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
@mysql_select_db($config['db_name']) or die( "Unable to select database");
$myFile = "videos.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$xml_txt .= '<?xml version="1.0" encoding="utf-8"?>';
$xml_txt .= '<videos>';
$query = mysql_query("SELECT `value` FROM `jr_jryoutube_item_key` WHERE `key` = "youtube_id"");
{
$xml_txt .= '<youtube media="http://ift.tt/mkzSv0 $query. autoplay="true">'
'</youtube>';
}
$rss_txt .= '</videos>';
fwrite($fh, $xml_txt);
fclose($fh);
?>



No comments:

Post a Comment