Table update problem! Both tables contain the serial number and device type fields. I want to update the device type value in table 2 as the device type value with the same serial number in Table 1. how can I write it? ------ Solution ------------------ $ SQL & #39; SELECT * FROM Table 2 & #39; $ resmysql_query ($ SQL) ordie (& #39; Queryfailed table update problem!
Both tables contain the serial number and device type fields.
I want to update the device type value in table 2 as the device type value with the same serial number in Table 1. how can I write it?
------ Solution --------------------
$ SQL = 'select * FROM table 2 ';
$ Res = mysql_query ($ SQL) or die ('query failed: '. mysql_error ());
While ($ row = mysql_fetch_array ($ res )){
$ Sql1 = "SELECT * FROM Table 1 where serial number = $ row ['serial number '] limit 1 ";
$ Res1 = mysql_query ($ sql1) or die ('query failed: '. mysql_error ());
While ($ row1 = mysql_fetch_array ($ res )){
$ Sql2 = "update table 2 set device type value = $ row1 ['device type value'] where serial number = $ row ['serial number ']";
Mysql_query ($ sql2 );
}
}
---------------
This is probably the meaning. Change it by yourself