Sorry in advance if this is already posted/answered ...
I am TRYING to write a modularized function for editting table values in a MySQL db that compares the current db $value for $field in $table with user inputted data such that the 'UPDATE' sent to MySQL contains the old data, a time/date stamp, and the new data.
I have created an associative array called $oldData that is the result of a MySQL query which pulls a single row from $table with the string identifiers being the field names of the table. There is a second associative array called $newData that is built using $_POST statements and has the same sting identifiers for the array as $oldData. I am using a 'switch' statement to define that which is unique to each table.
I need a loop of some form so I can test $oldData["field1"] against $newData["field1"]. I was hoping to use a foreach loop, but I don't know how/think it's not possible to have it do 2 arrays in parallel. Then I rewrote it with a while (below), but you can't put a variable inside a variable ($newData["{$fieldName}"]), so what I wrote below won't work. I did it more to illustrate what the heck it is that I want.
$count=0;
$oldData=mysql_query($sql1,$cn);
while ($fieldName=mysql_field_name($sql1,$count)) {
-->if ($oldData["{$fieldName}"] != $newData["{$fieldName}"]) {
------>$timeStamp=getdate();
------>$editDetails=" Editted @".$timeStamp["hours"].":".
------------>$timeStamp["minutes"].":".$timeStamp["seconds"].
------------>" on ".$timeStamp["weekday"].", ".$timeStamp["month"].
------------>", ".$timeStamp["mday"].", ".$timeStamp["year"]." ";
------>$fieldValue=$oldData["{$fieldName}"].$editDetails.$newData["{$fieldName}"];
------>$sql2="UPDATE {$table} SET {$fieldName}='{$fieldValue}' WHERE
------------>{$index}='{$newData["fieldName"]}'";
------>$result= mysql_query($sql2,$cn);
------>print ($result == TRUE) ? "Edit successful for {$fieldName}.<br>"
------------>: "Error editting {$fieldName}. Try again<br>" ;
---->}
-->else { print "New value same as old value for {$fieldName}"; }
-->$count++;
->}
Thx Much,
Al