Jump to content


xml - php - mysql


12 replies to this topic

#1 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 04 May 2006 - 03:01 PM

Ok here's a good one.

1. Is it possible to have an mp3 uploaded to a database?
Then along with the mp3 I would enter the song name and band.
2. Is it possible to have the xml get the info from the database somehow?

I would like to make a very user friendly mp3 player.
This way the user could run the php script to enter the table. No mysql knowledge needed.
Then have a form where you upload the mp3 and also enter the song/band name.

Thanks..Hooch

#2 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 04 May 2006 - 03:09 PM

1. Yes
2. Yes

B)

All the things you are asking can be done with PHP, MySQL, and XML

Edited by Chaos King, 04 May 2006 - 03:10 PM.


#3 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 04 May 2006 - 04:25 PM

Thank you Chaos, step 1 done!

I have been using FunkySoul's tut on mp3 players for awhile now.
So how would I impliment the xml/database connection from his script?
<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name="Pixel2Life Soundtrack 01" file="music/p2l_01.mp3" />
<song name="Twodded Soundtrack 01" file="music/twod_01.mp3" />
</songs>
Or is it more complicated, and I need to change the .swf and how it grabs
the info from the xml page?

tytytytyt very much

#4 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 05 May 2006 - 03:36 PM

I am not a big fanboy of using xml to recieve dynamic data in that way, but looking at it from a glace shows that as long as your script can interprit your xml data, there should be no problem in doing what you need to do.

#5 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 06 May 2006 - 10:52 PM

Could you please show me the code for executing this?
How would this code look to get an mp3 from a database?
<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name="Pixel2Life Soundtrack 01" file="music/p2l_01.mp3" />
<song name="Twodded Soundtrack 01" file="music/twod_01.mp3" />
</songs>

If this was my database..
<?php
include "includes/db.php";

$query = 'DROP TABLE `tunz`';
$result = mysql_query($query);

$query = 'CREATE TABLE `tunz` (
id int(11) NOT NULL auto_increment,
songname varchar(32) NOT NULL UNIQUE,
band varchar(32) NOT NULL,
mp3 varchar(32) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=INNODB;';

$result = mysql_query($query);
echo "Table Created!";
?>

Thank you..Hooch

#6 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 07 May 2006 - 07:38 AM

Okay, you would need to create an xml parser. What that would do is interpret the data set by the xml feed and gather the data from your database where specified. You could possibly do some preg_match's in order to gather the information you need from the feed. Since it is not a standard rss feed and it is custom to suit your needs, a normal rss reader won't work with this.

#7 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 15 May 2006 - 08:15 PM

Here's my progress

I changed my actionscript in the .swf to link to my new playlist.php.

The old playlist.xml looked like this..
<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name="Song" band="Band" File="music/Song.mp3" />
</songs>
I had the new playlist.php actually working off the database. But it will not work with my old .swf file.
Here's the code for the new playlist.php
<?php header ("content-type: text/xml"); 
print "<?xml version=\"1.0\"?>\n"; 
mysql_connect("localhost", "*****", "****") or die ("<b>Unable to establish connection with MySQL.</b>\n"); 
mysql_select_db("****") or die ("<b>Unable to locate specified database.</b>"); 

$query = "SELECT * FROM music ORDER BY track_id ASC"; 
$result = mysql_query($query); 
 
while($songs = mysql_fetch_object($result)) 
{	 
print "<songs>\n";	 
print "<name>".$songs->name."</name>\n";	 
print "<band>".$songs->band."</band>\n";
print "<File>".$songs->File."</File>";	 
print "</songs>\n"; 
} 
?>


Any ideas what I am doing wrong?

Thank you..

#8 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 15 May 2006 - 09:22 PM

I have a tutorial on something like this, except its a .php file for and rss feed. close to what you are looking for.

http://darkpixels.ne...orial/php/id/6/

#9 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 16 May 2006 - 12:32 PM

With a little more reading I have a question.
The original actionscript (by funkysoul) for the childNodes are as follows...
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songFile = [];
		for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
		_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
		_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
		_global.songFile[i] = playlist.firstChild.childNodes[i].attributes.File;

This is in conjunction with the following xml..
<?xml version='1.0' encoding='utf-8'?>
<songs>
<song name="Song" band="Band" File="music/Song.mp3" />
</songs>

Now would I need to change the above actionscipt for the following playlist.php?
<?php header ("content-type: text/xml"); 
print "<?xml version=\"1.0\"?>\n"; 
mysql_connect("localhost", "*****", "****") or die ("<b>Unable to establish connection with MySQL.</b>\n"); 
mysql_select_db("****") or die ("<b>Unable to locate specified database.</b>"); 

$query = "SELECT * FROM music ORDER BY track_id ASC"; 
$result = mysql_query($query); 

while($songs = mysql_fetch_object($result)) 
{	 
print "<songs>\n";	 
print "<name>".$songs->name."</name>\n";	 
print "<band>".$songs->band."</band>\n";
print "<File>".$songs->File."</File>";	 
print "</songs>\n"; 
} 
?>

Anyone see some correction needed??

#10 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 16 May 2006 - 02:00 PM

<?php header ("content-type: text/xml"); 
print "<?xml version=\"1.0\"?>\n"; 
mysql_connect("localhost", "*****", "****") or die ("<b>Unable to establish connection with MySQL.</b>\n"); 
mysql_select_db("****") or die ("<b>Unable to locate specified database.</b>"); 

$query = "SELECT * FROM music ORDER BY track_id ASC"; 
$result = mysql_query($query); 

while($songs = mysql_fetch_object($result)) 
{	 
print "<songs>\n";
print "<song name=".$songs->name." band=".$songs->band." File=".$songs->File." />\n";
print "</songs>\n"; 
} 
?>
That's using the xml format funkysoul used, give it a try

#11 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 16 May 2006 - 06:32 PM

Hey Halopro, I tried that exact code too.
but it was a no go.
Here's the error...
The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 


--------------------------------------------------------------------------------

A string literal was expected, but no opening quote character was found. Error processing resource 'http://www.@@@@.c/s...

<song name=song01 band=band01 File=music/song01.mp3 />
-----------^

Hmmm...

**I was wondering if this needs to be changed in the action script since the playlist is in a php file instead of xml
playlist = new XML();

Edited by Hooch, 16 May 2006 - 07:33 PM.


#12 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 17 May 2006 - 06:49 PM

ok, I got my playlist.php to pop out the exact info the playlist.xml does.
Here's my playlist.php
<?php 
header ("content-type: text/xml"); 
print "<?xml version=\"1.0\"?>\n"; 
mysql_connect("localhost", "*****", "*****") or die ("<b>Unable to establish connection with MySQL.</b>\n"); 
mysql_select_db("*****") or die ("<b>Unable to locate specified database.</b>"); 

$query = "SELECT * FROM music ORDER BY track_id ASC"; 
$result = mysql_query($query); 
print "<songs>\n";
while($songs = mysql_fetch_object($result)) 
{  
print "<song name=\"".$songs->name."\" band=\"".$songs->band."\" File=\"".$songs->File."\" />\n";
} 
print "</songs>";
?>

This will produce
  <?xml version="1.0" ?> 
- <songs>
  <song name="song01" band="band01" File="music/song01.mp3" /> 
  <song name="song02" band="band02" File="music/song02.mp3" /> 
  </songs>
But it still will not work with my mp3 player.
Once my playlist.php is equal to my playlist.xml do I need to change anything else?
I changed the link from my actionscript from playlist.xml to playlist.php

Thanks for any help
Hooch

#13 Hooch

    Young Padawan

  • Members
  • Pip
  • 158 posts
  • Location:Brockville, Ontario

Posted 17 May 2006 - 08:13 PM

It would not work from my existing browser.
Once I tried from a new browser, it worked perfect!!

Thanks for all the help guys!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users