Hello. There was a need to transfer field values from one table to another by comparing data. Here is an example of a table table1
Table1ID Table1Name
- Textbook
- Notebook
- Textbook
- Textbook
Example table table2
Table2ID Name Nameid
- A pen
- Notebook
- Textbook
- Textbook
Task: Compare 2 tables, if the Name values in the fields are the same, then add the id from table1 to the Nameid field from table2. I use Mysql and php My code
$query = "SELECT * FROM table1 , table2 WHERE Table1Name = Table2Name"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $query2 = "UPDATE table2 SET Table2Name=".$row[Table1ID]." WHERE Table1Name = Table2Name"; mysql_query($query2); }