Jump to content

Best way to update a recod


rondog

Recommended Posts

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

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.

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)

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)

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.