janim Posted May 8, 2008 Share Posted May 8, 2008 Hi guys how can i know what attributes has been modified after mysql_query ? let's say i have this table id name email password 1 aa @ **** 2 bb @ **** 3 cc @ **** 4 dd @ **** and i updated it : mysql_query("update table set name = '$name',email='$mail',password='$pas' where id='2'"); so how can i know wich attributes has been modified ? i.e which ones has been changed ? ,let's suppose the new data is : cc ,@,**** . so just name has been changed ! see? how can i know this dynamically mysql_affected_rows return the number of fields and so on mysql_info(); any comment are welcome , thanks Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/ Share on other sites More sharing options...
rhodesa Posted May 8, 2008 Share Posted May 8, 2008 I don't think you can with the query. As far as MySQL is concerned, you are overwriting all the values. You could do a compare with PHP first. That would involve selecting the values, using strcmp() to see what has changed, then writing the ones that have. Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/#findComment-536075 Share on other sites More sharing options...
benphp Posted May 8, 2008 Share Posted May 8, 2008 Select the record first and compare the results with your update values if ($formVal == $dbVal) { print "$formVal was updated"; } Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/#findComment-536079 Share on other sites More sharing options...
rhodesa Posted May 8, 2008 Share Posted May 8, 2008 Select the record first and compare the results with your update values if ($formVal == $dbVal) { print "$formVal was updated"; } that won't work...he is saying: the value in the DB is 'abc', and then 'abc' is submitted again Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/#findComment-536088 Share on other sites More sharing options...
benphp Posted May 8, 2008 Share Posted May 8, 2008 Doesn't he want to see which fields were updated in the database? If so, he selects the database before updating, compares the db value with the submitted value, which shows him which fields are going to be updated. Then run the update. Or am I not understanding? Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/#findComment-536163 Share on other sites More sharing options...
rhodesa Posted May 8, 2008 Share Posted May 8, 2008 Doesn't he want to see which fields were updated in the database? If so, he selects the database before updating, compares the db value with the submitted value, which shows him which fields are going to be updated. Then run the update. Or am I not understanding? yes...that is what i said before...i read your other post as something different then the above Link to comment https://forums.phpfreaks.com/topic/104656-mysql_affected_rowsmysql_info/#findComment-536202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.