themistral Posted November 12, 2010 Share Posted November 12, 2010 Hi guys, I'm fairly sure this isn't going to be possible but hoping I'll be pleasantly surprised! I run an update query when a form is submitted. I want to be able to extract the fields that have actually been updated by the query... So for example if the update query is running on field_1, field_2 and field_3 but only field_2 is updated, I want to be able to find out that field_2 has been updated but field_1 and field_3 have not. Hope that makes sense! Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/ Share on other sites More sharing options...
ManiacDan Posted November 12, 2010 Share Posted November 12, 2010 If you're updating using a WHERE clause, then you can just run a SELECT with the same WHERE clause before your update and that will select the rows you're about to change. If you don't know which items are being updated, you can set a trigger on the table to update a "last_edited" timestamp on the table, which will allow you to fake the operation by selecting items that were updated in the last 2 seconds. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1133430 Share on other sites More sharing options...
themistral Posted November 13, 2010 Author Share Posted November 13, 2010 Thanks ManiacDan. But it's not the rows I need to know about...its the actual fields. My query will only return one row - I want to be able to find out which fields in that query have been updated... Using your 2nd bit of logic I could have a date field related to each field that could be updated and check that way, but it seems a log way around... Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1133756 Share on other sites More sharing options...
fenway Posted November 13, 2010 Share Posted November 13, 2010 I'm not sure I follow -- if you're issuing the update statement, then you know which fields were changed...? Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1133815 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 The select the row before you update it, and compare the current values of the row to what you're about to store in the update statement. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134419 Share on other sites More sharing options...
fenway Posted November 15, 2010 Share Posted November 15, 2010 The select the row before you update it, and compare the current values of the row to what you're about to store in the update statement. -Dan Not even necessary -- you have the ID already! Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134568 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 Not even necessary -- you have the ID already!But I'm assuming he doesn't have the VALUES. He said he's trying to do something like "the following fields were updated." Even with the ID, he'll need to select the whole row to figure out the differences. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134579 Share on other sites More sharing options...
themistral Posted November 15, 2010 Author Share Posted November 15, 2010 I have a form populated with values from the row id. If someone then updates the record using the form, I want to know if there is a nice easy way when running the query which fields have been updated. Yes I can check the original values against the posted values - that is what I have done for the moment, but I want to know if there is an easier way of finding out which fields have been affected by that update query... Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134664 Share on other sites More sharing options...
mikosiko Posted November 15, 2010 Share Posted November 15, 2010 No Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134674 Share on other sites More sharing options...
themistral Posted November 15, 2010 Author Share Posted November 15, 2010 Fair enough! Just wanted to check really! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/218477-get-the-id-of-the-fields-updated-by-an-update-query/#findComment-1134676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.