Jump to content

User add fields in form question


herghost

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 tracks
i 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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.