我如何转置INSERT语句

目前,当我将数据插入表中时看起来像这样。

php - 如何转置Mysql INSERT语句?-LMLPHP

但是我想插入如下

 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)");
}

最佳答案

请尝试以这种方式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)");
}

10-06 02:38