Jump to content

[SOLVED] Updating a 1 to many relationship


chronister

Recommended Posts

Hi All,

I am creating a php/mysql website for my aunt's extensive karaoke library. I have a form that accepts various info for each disk, and a list of songs contained on that disk.

I have a disk table and a songs table. The songs table references the did (disk id) to relate the songs with a particular disk. My question is this....

When I edit information for a particular disk, disk info goes to the disk table, and songs go to the songs table.  The only way I know to do this is to upon submit, simply delete all songs for that particular id and re-insert the info from the form.

I am not sure how to update the songs that have been changed while skipping the ones that have not without creating lots and lots more code and making the process take a long time. I used this technique for my wife's recipe database, and it's easy, but I know that it is not the "proper way" to do it.

If you need more info I will be happy to provide it.

Any help is appreciated

Thanks,
Nathan
Link to comment
Share on other sites

I think deletion and re-creating is the way to go.  There's always a tradeoff between simplicity of code and efficiency, and since there's no more than 20 songs on a CD, the loss in efficiency is negligible.  There's no point optimizing something that doesn't need optimizing :)
Link to comment
Share on other sites

Excellent,

Thank You.

This is going to be for less than 5 users, so the server load is not a big factor. I am simply trying to learn the "proper way" to do things. Could you point me to any kind of article or resource that touches on this subject so that I can learn the proper way to do this if need be in the future?
Link to comment
Share on other sites

Fenway,

what do you mean. I am still trying to figure out the ins and outs of MySql. The only way I can see to do it is using a lot of code......receive the items submitted from the form then 1 by 1 compare them to the items in the table and if there is a change then update that item. That really seems like a lot of extra bulky code that I am not real sure how to do. I figure there must be a built in mysql function to do something like this.

thus far, almost every complicated thing I wanted to do, had a function in either php or mysql to really simplify it.

For my purposes, the delete then recreate is fine, but I would like to learn the proper way to do it.

If you would explain that in a little more detail I would appreciate it Fenway..

Thanks for the Help All

Nathan
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.