Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

creating a playlist using php

hey guys so I have this code thats prints out various aspects of a song and im looking to put these aspects into a playlist with the format
<playlist>
 <item>
  <filename>'file'<filename/>
  <song>'songname'<song/>
  <artist>'artistname'<artist/>
 </item>
</playlist>

include("connectionfile.php");

$query = "SELECT id, song_title, song_artist, genre, filepath FROM music ORDER BY song_artist";
$result = mysql_query($query) or die("error in the query");

   

while ($songs = mysql_fetch_assoc($result))
{
        // THE SONG NAME WILL BE FOUND HERE
        $my_id = $songs["id"];
           
           
            $mysong=$songs["song_title"];
            $myartist=$songs["song_artist"];
            $thegenre=$songs["genre"];
            $thefilepath=$songs["filepath"];
           
        echo "<br/>$my_id" . PHP_EOL;
            echo "<br />$mysong" . PHP_EOL;
            echo "<br/>$myartist" . PHP_EOL;
            echo "<br/>$thegenre" . PHP_EOL;
            echo "<br/>$thefilepath" . PHP_EOL;


}

thanks for any help guys.
0
jvsmooth
Asked:
jvsmooth
  • 2
  • 2
1 Solution
 
Lukasz ChmielewskiCommented:
Try

<?php

include("connectionfile.php");

$query = "SELECT id, song_title, song_artist, genre, filepath FROM music ORDER BY song_artist";
$result = mysql_query($query) or die("error in the query");

    
echo"&lt;playlist&gt;";

while ($songs = mysql_fetch_assoc($result))
{
    echo"&lt;item&gt;";

        // THE SONG NAME WILL BE FOUND HERE
        $my_id = $songs["id"];
            
            $mysong=$songs["song_title"];
            $myartist=$songs["song_artist"];
            $thegenre=$songs["genre"];
            $thefilepath=$songs["filepath"];
            
            echo"&lt;filename&gt;".$thefilepath."&lt;/filename&gt;".PHP_EOL;
            echo"&lt;song&gt;".$mysong."&lt;/song&gt;".PHP_EOL;
            echo"&lt;artist&gt;".$myartist."&lt;/artist&gt;".PHP_EOL;
            
    echo"&lt;/item&gt;";

}

echo"&lt;/playlist&gt;";

?>

Open in new window

0
 
Lukasz ChmielewskiCommented:
I did not test it, but if you want to wrap everything into a xml file playlist.xml, try this way:

<?php

include("connectionfile.php");

$query = "SELECT id, song_title, song_artist, genre, filepath FROM music ORDER BY song_artist";
$result = mysql_query($query) or die("error in the query");

$filestring = "&lt;?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?&gt;";  
$filestring .= "&lt;playlist&gt;";

while ($songs = mysql_fetch_assoc($result))
{
    $filestring .= "&lt;item&gt;";

        // THE SONG NAME WILL BE FOUND HERE
        $my_id = $songs["id"];
            
            $mysong=$songs["song_title"];
            $myartist=$songs["song_artist"];
            $thegenre=$songs["genre"];
            $thefilepath=$songs["filepath"];
            
            $filestring .= "&lt;filename&gt;".$thefilepath."&lt;/filename&gt;".PHP_EOL;
            $filestring .= "&lt;song&gt;".$mysong."&lt;/song&gt;".PHP_EOL;
            $filestring .= "&lt;artist&gt;".$myartist."&lt;/artist&gt;".PHP_EOL;
            
    $filestring .= "&lt;/item&gt;";

}

$filestring .= "&lt;/playlist&gt;";


file_put_contents("playlist.xml",$filestring);
?>

Open in new window

0
 
jason987Commented:
Just add it into the echos or replace them?
....
            echo "<playlist>"
            echo " <item>"
            echo "<br/><filename>$thefilepath<filename/>" . PHP_EOL;
            echo "<br /><song>$mysong<song/>" . PHP_EOL;
            echo "<br/> <artist>$myartist<artist/>" . PHP_EOL;
            echo "</playlist>"
            echo " </item>"
....
   
 
0
 
jason987Commented:
there's some missing terminators above:

            echo "<br/><playlist>";
            echo " <br/><item>";
            echo "<br/><filename>$thefilepath<filename/>" . PHP_EOL;
            echo "<br /><song>$mysong<song/>" . PHP_EOL;
            echo "<br/> <artist>$myartist<artist/>" . PHP_EOL;
            echo "<br/></playlist>";
            echo "<br/> </item>";
0
 
jvsmoothAuthor Commented:
phenomenal thank so much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now