herghost Posted April 26, 2009 Share Posted April 26, 2009 Hi all, is something like this possibel? I want a user to be able to upload the discography of an band, they should be able to upload the album name, album cover and names of tracks. However, the amount of albums/tracks can vary from band to band, is it possible to have a form where the user clicks a button to 'add' a new album, and for it then to give 12 track fields as defualt, but with a button to 'add' new fields? How would I do this in a mysql database? Would I have to create all the fields manually? Or could I ask the php page to create a new field? Cheers Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/ Share on other sites More sharing options...
mrMarcus Posted April 26, 2009 Share Posted April 26, 2009 you could have a field in the db that stores the 'tracks' as an array, ie. track1|track2|track3 and so on (| being the delimiter.) and adding one more field to the form with PHP is no problem either .. just throw your fields in a loop, ie. for ($i=1; $i <= $num_fields; $i++) { have an 'Add Field' button in the form, and when clicked, the PHP updates the $num_fields var by adding one (1) to it, ultimately upping your $i <= $num_fields from 12 (default), to 13 .. and so on .. or something like that. Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/#findComment-819634 Share on other sites More sharing options...
DjMikeS Posted April 26, 2009 Share Posted April 26, 2009 mrMarcus has a point, but by doing it that way is not really considered a best practice... What you want is an extra table eg. album_tracks You then create a field eg. album_id which belongs to a table where you store the albums... That way you can insert as many tracks as you want without having to create an array to insert or exploding the array to retrieve... Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/#findComment-819638 Share on other sites More sharing options...
GingerRobot Posted April 26, 2009 Share Posted April 26, 2009 you could have a field in the db that stores the 'tracks' as an array, ie. track1|track2|track3 and so on (| being the delimiter.) Please don't do that. It's a very bad idea. What happens when you also want to store information about the track? What about if you wish to search by track name? You'll need a second table. mrMarcus, you might like to read up on database normalization. As for the question at hand, if you wish to do this in a nice, smooth manner you'll need to use some javascript - if you're happy with a page reload, have some buttons submit to the same page. Repopulate the forms with the current information and add a new input to your form. Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/#findComment-819642 Share on other sites More sharing options...
mrMarcus Posted April 26, 2009 Share Posted April 26, 2009 you could have a field in the db that stores the 'tracks' as an array, ie. track1|track2|track3 and so on (| being the delimiter.) Please don't do that. It's a very bad idea. What happens when you also want to store information about the track? What about if you wish to search by track name? You'll need a second table. mrMarcus, you might like to read up on database normalization. As for the question at hand, if you wish to do this in a nice, smooth manner you'll need to use some javascript - if you're happy with a page reload, have some buttons submit to the same page. Repopulate the forms with the current information and add a new input to your form. simple questions get simple answers .. had the initial question asked for input on how to also store information on tracks and so on, an appropriate answer would've been given.they should be able to upload the album name, album cover and names of tracksi take things as they come .. if i was to mentally invest 100% into every question here, i'd be a vegetable. if people want more specific answers, ask more specific questions. now, i do agree with db normalization on a whole, but for small-time projects, what i suggested will suffice. Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/#findComment-819653 Share on other sites More sharing options...
herghost Posted April 26, 2009 Author Share Posted April 26, 2009 Thanks for all your answers so far, I can see I have a lot of further reading! On another note, you know when in windows media player etc you can search for an album and it will pull all the track names etc from a database, is this information open source, do you think an app could be developed to use this information and insert it into my database? Link to comment https://forums.phpfreaks.com/topic/155715-user-add-fields-in-form-question/#findComment-819658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.