Home  >  Article  >  Backend Development  >  表更新有关问题

表更新有关问题

WBOY
WBOYOriginal
2016-06-13 13:51:30774browse

表更新问题!
两张表都包含序列号、设备类型字段。
我现在想更新表二的设备类型值为表一相同序列号的设备类型值,请教怎么写?

------解决方案--------------------
$sql = 'SELECT * FROM 表2 ';
$res = mysql_query($sql) or die( 'Query failed: ' . mysql_error());
while($row = mysql_fetch_array($res)){
$sql1 = "SELECT * FROM 表1 where 序列号=$row[ '序列号 '] limit 1 ";
$res1 = mysql_query($sql1) or die( 'Query failed: ' . mysql_error());
 while($row1 = mysql_fetch_array($res)){
  $sql2 = "update 表2 set 设备类型值=$row1[ '设备类型值 '] where 序列号=$row[ '序列号 '] ";
mysql_query($sql2);
}
}
---------------
大概就是这么个意思。自己改改吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn