AE117 Posted April 16, 2009 Share Posted April 16, 2009 Ok What I need is a simple php code that can output xml that looks like <?xml version="1.0" encoding="utf-8"?> <featureset> <album name="Shock Value" author="Timbaland" imageUrl="images/Timbaland/image.jpg" link="http://flabell.com/"> <song name="Oh Timbaland" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Give It To Me" duration="3 : 54" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Release" duration="2 : 48" buy="false" download="true" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="The Way I Are" duration="2 : 50" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Bounce" duration="4 : 04" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Come And Get Me" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Kill Yourself" duration="4 : 07" buy="false" download="false" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="Boardroom" duration="2 : 29" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> </album> </featureset> Heres the thing I am pulling information off of a database to fill in the fields author image url etc. In addition to that the Album will also be pulled from a database so if there is more then one album it needs to pull more info example: <?xml version="1.0" encoding="utf-8"?> <featureset> <album name="Shock Value" author="Timbaland" imageUrl="images/Timbaland/image.jpg" link="http://flabell.com/"> <song name="Oh Timbaland" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Give It To Me" duration="3 : 54" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Release" duration="2 : 48" buy="false" download="true" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="The Way I Are" duration="2 : 50" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Bounce" duration="4 : 04" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Come And Get Me" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Kill Yourself" duration="4 : 07" buy="false" download="false" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="Boardroom" duration="2 : 29" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> </album> <album2 name="Shock Value" author="Timbaland" imageUrl="images/Timbaland/image.jpg" link="http://flabell.com/"> <song name="Oh Timbaland" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Give It To Me" duration="3 : 54" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Release" duration="2 : 48" buy="false" download="true" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="The Way I Are" duration="2 : 50" buy="false" download="false" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Bounce" duration="4 : 04" buy="false" download="true" downloadSource="download/song1.mp3">songs/song1.mp3</song> <song name="Come And Get Me" duration="3 : 31" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> <song name="Kill Yourself" duration="4 : 07" buy="false" download="false" downloadSource="download/song1.mp3">songs/song3.mp3</song> <song name="Boardroom" duration="2 : 29" buy="false" download="true" downloadSource="download/song1.mp3">songs/song2.mp3</song> </album2> </featureset> I am using this php on a testing database which looks like <?php header("Content-type: text/xml"); $host = ""; $user = ""; $pass = ""; $database = ""; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $query = "SELECT * FROM ost_media ORDER BY media_id DESC"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output .= "<featureset>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t\t<date>" . $row['media_id'] . "</date>\n"; // Escaping illegal characters $row['text'] = str_replace("&", "&", $row['text']); $row['text'] = str_replace("<", "<", $row['text']); $row['text'] = str_replace(">", ">", $row['text']); $row['text'] = str_replace("\"", """, $row['text']); $xml_output .= "\t\t<title>" . $row['media_title'] . "</title>\n"; echo $test; } $xml_output .= "</featureset>"; echo $xml_output; ?> and gives the xml output <featureset> <date>106</date> <title>Ronix Ibex Wakeboard 2009 Both Sides</title> <date>105</date> <title>Ibex - Parks Bonify</title> <date>104</date> <title>Big Turbo</title> <date>103</date> <title>Suzuki Baleno</title> <date>102</date> <title>Toyota Supra</title> <date>101</date> <title>Probe vs WRX ( Probe has NOS)</title> <date>100</date> <title>93 Probe vs WRX</title> <date>99</date> <title>S2000 vs RSX-S</title> <date>98</date> </feature> I am having a problem creating an array with this that looks like the array in the first xml. Please point me in the right direction thank you. Link to comment https://forums.phpfreaks.com/topic/154312-using-php-to-output-xml-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.