Solved

creating a playlist using php

Posted on 2011-02-25
5
457 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now