Solved

creating a playlist using php

Posted on 2011-02-25
5
462 Views
Last Modified: 2012-05-11
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
Comment
Question by:jvsmooth
  • 2
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34983187
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
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 34983227
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
 
LVL 5

Expert Comment

by:jason987
ID: 34983234
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
 
LVL 5

Expert Comment

by:jason987
ID: 34983258
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
 

Author Closing Comment

by:jvsmooth
ID: 34984386
phenomenal thank so much
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question