我如何转置Mysql INSERT语句?

时间:2016-04-16 03:38:44

标签: php mysql

我如何转置INSERT语句

目前在表格中插入我的数据时如下所示。

enter image description here

但我想按以下方式插入

 bomItem      partID
 600000      500000     
 600000      200000
 600000      100000
 600204      500210
 600204      201862
 600204      100202
 600206      500204
 600206      201748
 600206      100202
   .           .
   .           .
   .           .

我有以下代码将数据从一个数据库插入另一个数据库(Mysql)表

 $recordd = $tv->search(3000254898, 's=2');

 foreach($recordd as $data2) {
  $itemid = $data2['fields']['STOCK NO'];
  $bomwheel = $data2['fields']['BOM WHEEL PN'];
  $bomtire = $data2['fields']['BOM TIRE PN'];
  $bomvalve = $data2['fields']['BOM VALVE PN'];
  $result = mysqli_query($con,"INSERT INTO assy   (ItemID,bom1w,bom2t,bom3v) VALUES ($itemid, $bomwheel, $bomtire,$bomvalve)"); 
}

1 个答案:

答案 0 :(得分:0)

请尝试这种方式3分别插入$ itemid在所有情况下都相同:

foreach($recordd as $data2) {
   $itemid = $data2['fields']['STOCK NO'];
   $bomwheel = $data2['fields']['BOM WHEEL PN'];
   $bomtire = $data2['fields']['BOM TIRE PN'];
   $bomvalve = $data2['fields']['BOM VALVE PN'];
   mysqli_query($con,"INSERT INTO assy(ItemID,bom1w) VALUES($itemid, $bomwheel)");
   mysqli_query($con,"INSERT INTO assy(ItemID,bom2t) VALUES($itemid, $bomtire)");
   mysqli_query($con,"INSERT INTO assy(ItemID,bom3v) VALUES($itemid, $bomvalve)"); 
}