I have a bit of problem with my code at the moment and I hope you can help me with it.
First of the tabels
SELECT artist, album, song
FROM artist
LEFT JOIN album
on artist.artist_ID = album.artist_ID
LEFT JOIN song
on album.album_ID = song.album_ID
ORDER BY artist.artist, album.album_ID, song.song_ID
Im trying to export it as an XML with help of php so im creating the XML direct in the document so i just can press a link to view and access the xml. But the problem im having is that the song dont stack under album. Instead they do this:
<music>
<artist name="$artist1">
<album name="$album1">
<song>$song1</song>
</album>
</artist>
</music>
<music>
<artist name="$artist1">
<album name="$album1">
<song>$song2</song>
</album>
</artist>
</music>
I want then to stack like this:
<music>
<artist name="$artist1">
<album name="$album1">
<song>$song1</song>
<song>$song2</song>
<song>$song3</song>
</album>
</artist>
</music>
This is the PHP-code i use at the moment to export to XML, something dont work here. I have been trying to fix it the last 12 hours without luck.
$export = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$export="<myTunes>";
while($row = mysqli_fetch_array($result))
{
$export.="<music>";
$artist=$row["artist"];
$album=$row["album"];
$song=$row["song"];
$export.=" <artist name='$artist'>
<album name='$album'>
<song>$song</song>
</album>
</artist>";
$export.="</music>";
}
$export.="</myTunes>";
file_put_contents("export.xml", $export);
echo "<a href='export.xml' target='_blank'>Export database as XML</a>";
Please help if you can, im starting to loose my mind over here. Best Regards, Chris