rondog Posted November 26, 2010 Share Posted November 26, 2010 I have some entries in my db and when I go to edit the entry, I have a form that is populated with the values tied to whatever ID they clicked. What is the best method for determining which fields need to be updated? Should I just update all of them regardless if they changed or not? Link to comment https://forums.phpfreaks.com/topic/219862-best-way-to-update-a-recod/ Share on other sites More sharing options...
revraz Posted November 26, 2010 Share Posted November 26, 2010 I would Link to comment https://forums.phpfreaks.com/topic/219862-best-way-to-update-a-recod/#findComment-1139714 Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 Yeah, that's really the only way to do it efficiently. Otherwise you're looking at processing every form field with php to see if any are the same as when they were populated, and dynamically building the query string to not include fields that aren't different. Much less code to just submit all of them, and let MySQL handle it. Link to comment https://forums.phpfreaks.com/topic/219862-best-way-to-update-a-recod/#findComment-1139761 Share on other sites More sharing options...
The Little Guy Posted November 26, 2010 Share Posted November 26, 2010 I have some entries in my db and when I go to edit the entry, I have a form that is populated with the values tied to whatever ID they clicked. What is the best method for determining which fields need to be updated? Should I just update all of them regardless if they changed or not? Yes, I believe mysql ignores data that is the same as the data you pass to it anyway. So if you have a row with values like this: 123 234 345 and then do an update with values like this: 123 abc 345 The only thing mysql will read is the abc and ignore the rest. If you do something like this as an update (instead of abc): 123 234 345 Mysql won't do anything, except say "0 rows were affected" (or something similar) Link to comment https://forums.phpfreaks.com/topic/219862-best-way-to-update-a-recod/#findComment-1139799 Share on other sites More sharing options...
rondog Posted November 26, 2010 Author Share Posted November 26, 2010 I have some entries in my db and when I go to edit the entry, I have a form that is populated with the values tied to whatever ID they clicked. What is the best method for determining which fields need to be updated? Should I just update all of them regardless if they changed or not? Good to know, thanks. Yes, I believe mysql ignores data that is the same as the data you pass to it anyway. So if you have a row with values like this: 123 234 345 and then do an update with values like this: 123 abc 345 The only thing mysql will read is the abc and ignore the rest. If you do something like this as an update (instead of abc): 123 234 345 Mysql won't do anything, except say "0 rows were affected" (or something similar) Link to comment https://forums.phpfreaks.com/topic/219862-best-way-to-update-a-recod/#findComment-1140034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.