Note that there are some explanatory texts on larger screens.

plurals
  1. POexport XML from mySQL with PHP
    primarykey
    data
    text
    <p>I have a bit of problem with my code at the moment and I hope you can help me with it.</p> <p>First of the tabels</p> <pre><code>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 </code></pre> <p>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:</p> <pre><code>&lt;music&gt; &lt;artist name="$artist1"&gt; &lt;album name="$album1"&gt; &lt;song&gt;$song1&lt;/song&gt; &lt;/album&gt; &lt;/artist&gt; &lt;/music&gt; &lt;music&gt; &lt;artist name="$artist1"&gt; &lt;album name="$album1"&gt; &lt;song&gt;$song2&lt;/song&gt; &lt;/album&gt; &lt;/artist&gt; &lt;/music&gt; </code></pre> <p>I want then to stack like this: </p> <pre><code>&lt;music&gt; &lt;artist name="$artist1"&gt; &lt;album name="$album1"&gt; &lt;song&gt;$song1&lt;/song&gt; &lt;song&gt;$song2&lt;/song&gt; &lt;song&gt;$song3&lt;/song&gt; &lt;/album&gt; &lt;/artist&gt; &lt;/music&gt; </code></pre> <p>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. </p> <pre><code>$export = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;\n"; $export="&lt;myTunes&gt;"; while($row = mysqli_fetch_array($result)) { $export.="&lt;music&gt;"; $artist=$row["artist"]; $album=$row["album"]; $song=$row["song"]; $export.=" &lt;artist name='$artist'&gt; &lt;album name='$album'&gt; &lt;song&gt;$song&lt;/song&gt; &lt;/album&gt; &lt;/artist&gt;"; $export.="&lt;/music&gt;"; } $export.="&lt;/myTunes&gt;"; file_put_contents("export.xml", $export); echo "&lt;a href='export.xml' target='_blank'&gt;Export database as XML&lt;/a&gt;"; </code></pre> <p>Please help if you can, im starting to loose my mind over here. Best Regards, Chris</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload