I have two tables in MySQL, and each table has its own datetime field. I want to copy the datetime of table A to overwrite the datetime of table B. I use PHP.
$result = mysql_query("select *
from A
where id = $key");
$row = mysql_fetch_array($result);
print $row[2]."\n"; // $row[2] is the datetime field
mysql_query("update B
set date_cal = $row[2]
where id = $key") // try to overwrite datetime in table B
$row[2] has the string representation of datetime field.
But the overwrite operation does not take effect. How to do to overwrite datetime field of table B using php?
If I insist using $row[2] to assign the new datetime field rather running mysql_query again, how to do?
UPDATE b SET date_cal = (SELECT date_cal FROM a WHERE id = $key) WHERE id = $key."WHERE ID = $key"is valid, and PHP will replace$keywith its value.