herghost Posted April 13, 2009 Share Posted April 13, 2009 Hi all, I think this is what I want to do, however I would like some advice on if this is the correct way of doing things, and HOW to actually do it! Basically I have a webpage which pulls information on a band from a database depending on the user id, which is taken form the address bar. What I want to do is play a song in the background. I am guessing that putting the file in the sql database is a bad idea, so I am assuming that I create a folder on my server to store the files, and then somehow link the files in the mysql database. I am planning on playing them using the html embed tag. the table structure will basically be userid, song_name, mp3_link. Is this the best way to do this do you think? I think that I can select the song from the database and insert it into the embed tag. Any thoughts are code snippets would be great Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/ Share on other sites More sharing options...
jackpf Posted April 13, 2009 Share Posted April 13, 2009 What if a band had multiple songs? Maybe you should do something like, have a table for bands, and a table for songs. And each song has an ID that relates to their band. Just a suggestion. So, say a band id was 234. You could then do something like: $sql = "SELECT * FROM songs WHERE bandid='234'"; to grab all of that band's songs. Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808729 Share on other sites More sharing options...
herghost Posted April 13, 2009 Author Share Posted April 13, 2009 Thanks I understand that bit, its more of how do I put a link in a mysql database to my server? and can I make the script auto create folders for each band? Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808894 Share on other sites More sharing options...
jackpf Posted April 13, 2009 Share Posted April 13, 2009 Well if you have your songs in music/BAND_NAME/SONG , you could get them details by storing them in the database. So to get all the songs for a band, something like this: $band = $_GET['band']; $sql = mysql_query("SELECT * FROM songs WHERE band='$band'"); while($fetch = mysql_fetch_array($sql)) { $song = $fetch['song']; echo '<embed src="music/'.$band.'/'.$song.'" />'; } Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808898 Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 You're going to want to look into Database Normalization. If you want to make additional categories, features, classifications, etc. then it's much easier with a normalized database. Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808900 Share on other sites More sharing options...
laffin Posted April 13, 2009 Share Posted April 13, 2009 As Ive said in previous posts, u should look at the data and how to organize first. jackPf does make a good point in multiple songs for a band. u can even add genres, and so forth. but first design yer data fields and tables songs table (id, band id, genre id, title, url) band table (id, genre, name,) genre table (id, name) and so forth, by keeping the tables seperate, u will give yerself a bit more fleibility in the future. Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808902 Share on other sites More sharing options...
herghost Posted April 13, 2009 Author Share Posted April 13, 2009 Thanks to all of you, however it doesnt need to be all that complicated, I just need the one song to play. My main question I think is how do I store a link in mysql? Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808971 Share on other sites More sharing options...
jackpf Posted April 13, 2009 Share Posted April 13, 2009 Like this: song.mp3 And then use the code I posted above as a template. Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-808979 Share on other sites More sharing options...
laffin Posted April 13, 2009 Share Posted April 13, 2009 I think u should work on some php/mysql tutorials first to get to understand some of the concepts. cuz the hints here provided, and seems like ya want how to build the database, what fields/types to use. Quote Link to comment https://forums.phpfreaks.com/topic/153877-playing-music/#findComment-809033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.