chronister Posted December 30, 2006 Share Posted December 30, 2006 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 appreciatedThanks,Nathan Link to comment https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/ Share on other sites More sharing options...
btherl Posted December 30, 2006 Share Posted December 30, 2006 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 https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/#findComment-149737 Share on other sites More sharing options...
chronister Posted December 30, 2006 Author Share Posted December 30, 2006 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 https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/#findComment-149741 Share on other sites More sharing options...
fenway Posted December 30, 2006 Share Posted December 30, 2006 Well, you can update the ones with a UID directly, shouldn't ever have to delete anything. Link to comment https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/#findComment-149986 Share on other sites More sharing options...
chronister Posted December 31, 2006 Author Share Posted December 31, 2006 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 AllNathan Link to comment https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/#findComment-150200 Share on other sites More sharing options...
fenway Posted December 31, 2006 Share Posted December 31, 2006 When you display the info, and populate what I assume are form text inputs, you can simply "mark" each one with the uid of the record it came from so you can "find it" again. Link to comment https://forums.phpfreaks.com/topic/32254-solved-updating-a-1-to-many-relationship/#findComment-150441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.