Solved

creating a playlist using php

Posted on 2011-02-25
5
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

739 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