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
https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/
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 :)
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?
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.