herghost Posted May 4, 2009 Share Posted May 4, 2009 Hi all, how would you upload track information into a database? Obvioulsy the amount of tracks will vary per album uploaded and I was wondering the best way to acheive this. The end result being that I would like to echo out the information like: 1. Track 1 name 2. Track 2 name etc The only uploading I have done has just been through a PHP form and then inserting it into a database. How would you go about this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 So what other way do you want to upload? Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825250 Share on other sites More sharing options...
herghost Posted May 4, 2009 Author Share Posted May 4, 2009 I am happy with the insert, but i dont know how the best way to do this for tracks is. If I basically call each field say t1 for track one and then t2 for track two etc, it is going to cause problems with undefied fields if i have 20 boxes but there are only 12 tracks, i would in effect have undefied fields on t13 to t20 if you see what I mean Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825255 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 I would have JavaScript operate the number of input boxes. But you can always check using PHP to see if the input box is empty or not. This is how I would do it: <form method="post" name="tracks"> <input id="1" type="hidden" name="tracks_count" value="0" /> </form> <script type="text/javascript"> var trackcount = 1; var trackform = document.forms.tracks; function addTrackField () { trackform.innerHTML += '<input type="text" name="track' + trackcount + '" />'; trackform.tracks_count.value = ((int) trackform.tracks_count.value) + 1; trackcount++; } <script> <a href="javascript:addTrackField(); return false;">Add track</a> Then for PHP, I can grab the tracks_count field and loop. Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825256 Share on other sites More sharing options...
fry2010 Posted May 4, 2009 Share Posted May 4, 2009 you could store them as CSV's. In just one column. So say CD TITLE, CD TRACKS. and thats it. Then store them by appending a comma in between each track name. All you then have to do to find out the number of tracks is split them using explode(). Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825258 Share on other sites More sharing options...
herghost Posted May 4, 2009 Author Share Posted May 4, 2009 Thanks to both of you, Ken, how would I do this in the database? 1 x Long Text field? Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825263 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Do what in the database? Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825265 Share on other sites More sharing options...
herghost Posted May 4, 2009 Author Share Posted May 4, 2009 store the track information. perhaps I have missed the point, I have only been dabbling in pphp for the last few weeks, there is a lot i dont understand! Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825267 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Well you set up the table and run an INSERT SQL. Google. Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825269 Share on other sites More sharing options...
herghost Posted May 4, 2009 Author Share Posted May 4, 2009 yeah I get that.... Basically the output of this javascript, does it give every track an variable? or will all the tracks be in one? Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825272 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Try it out. Put it on your page. The JavaScript just adds a field. Of course, you would want to modify it a bit. The form keeps track of the total number of tracks you added in the form. Quote Link to comment https://forums.phpfreaks.com/topic/156720-uploading-cd-details-to-a-mysql-database-advice/#findComment-825282 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.