marSoul
June 25th, 2007, 08:40 AM
Hi,
I need to know how can i generate a playlist from mysql and php ?
I have a database that contains filename,artist,album and songname, i want an option that when a user want to listen to the specific album, php generate a playlist automatically in xml format so the player plays files one by one.
it would be nice if someone show me how to export a file in xml from my php page...
thanks
simplistik
June 25th, 2007, 09:09 AM
http://www.kirupa.com/web/mysql_xml_php.htm
blazes
June 25th, 2007, 09:12 AM
<?php
//init vars
$conn = mysql_connect('localhost', 'root', '');
//tests is my local db for testing. This is the name of your db
$db = mysql_select_db('tests', $conn);
$xml = '';
//query the db
$query = mysql_query('SELECT * FROM mp3s');
//loop through query results
while ( $row = mysql_fetch_array ( $query ) ){
//Add to xml
$xml .= "<song>\r\n";
$xml .= '<filename>' . $row['filename'] . "</filename>\r\n";
$xml .= '<artist>' . $row['artist'] . "</artist>\r\n";
$xml .= '<album>' . $row['album'] . "</album>\r\n";
$xml .= '<songname>' . $row['songname'] . "</songname>\r\n";
$xml .= "</song>\r\n";
}
//Write to playlist.xml in the same directory. Will override any other playist.xml file
$handle = fopen('playlist.xml', 'w+');
fwrite($handle, $xml);
?>
db dump:
CREATE TABLE `mp3s` (
`filename` varchar(255) NOT NULL,
`artist` varchar(255) NOT NULL,
`album` varchar(255) NOT NULL,
`songname` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `mp3s` (`filename`, `artist`, `album`, `songname`) VALUES
('test.mp3', 'blazes', 'blazes816', 'Test')
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.