C2K Posted June 8, 2007 Share Posted June 8, 2007 Hi, I want to create this xml file with different mySQL tables depending on one ID, this artistID (ArtistNameID) is the relation in the other tables... Now I want this xml file: <artiesten> <artiest> <naam>naamartiest</naam> <datum>datum</datum> <news> <newsitem> <titel>nieuws titel</titel> </newsitem> <newsitem> <titel>nieuws titel</titel> </newsitem> </news> </artiest> <artiest> <naam>naamartiest</naam> <datum>datum</datum> <news> <newsitem> <titel>nieuws titel</titel> </newsitem> <newsitem> <titel>nieuws titel</titel> </newsitem> </news> </artiest> </artiesten> There is more then one newsitem, then I want it nested in the xml output... if there is none then don't show. I did this so far... but isn't working <?php $dbcnx = @mysql_connect("localhost","**","**"); $dbselect = @mysql_select_db("***"); if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; } $query = "SELECT * FROM artist, news WHERE artist.ArtistNameID = news.ArtistNameID ORDER BY artist.ArtistNameID"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $query_news = "SELECT * FROM news WHERE news.ArtistNameID = 12345"; $result_news = mysql_query($query_news) or die('Query failed: ' . mysql_error()); header("content-type:text/xml;charset=utf-8"); echo "<export version='1'>\n"; echo " <title>Jan Vis Agency exportlist - exlstudio</title>\n"; echo " <info>http://www.janvis.nl/export/</info>\n"; echo " <artiesten>\n"; while($row = @mysql_fetch_array($result)) { echo " <artiest>\n"; echo " <id>".$row['ArtistNameID']."</id>\n"; echo " <name>".htmlspecialchars($row['ArtistNameName'])."</name>\n"; echo " <profile_text>".htmlspecialchars($row['ArtistNameBio'])."</profile_text>\n"; echo " <logo>http://www.janvis.nl/".htmlspecialchars($row['ArtistNameThumb'])."</logo>\n"; echo " <website>".htmlspecialchars($row['internet'])."</website>\n"; echo " <keywords>".htmlspecialchars($row['keywords'])."</keywords>\n"; echo " <discription>".htmlspecialchars($row['discription'])."</discription>\n"; if ($row>0) { $nested_query_news = str_replace("12345", $row['ArtistNameID'], $query_news); $row_news = mysql_fetch_assoc($news); $totalRows_news = mysql_num_rows($news); $nested_sw = false; if (isset($row_news) && is_array($row_news)) { do { //Nested repeat!!???? echo "<news>\n"; echo " <newsitem>".htmlspecialchars($row_news['ArtistNameID'])."</newsitem>\n"; echo "</news>\n"; while ($row_news = mysql_fetch_assoc($query_news)) } } } echo " <lastchange>".htmlspecialchars($row['ArtistNameDate'])."</lastchange>\n"; echo " </artiest>\n"; } echo " </artiesten>\n"; echo "</export>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54744-nested-loop-xml-export/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.