Link to home
Start Free TrialLog in
Avatar of jvsmooth
jvsmooth

asked on

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.
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

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

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jason987
jason987

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>"
....
   
 
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>";
Avatar of jvsmooth

ASKER

phenomenal thank so much