Kin Kin - 7 months ago 24
SQL Question

How can i Transpose Mysql INSERT Statement?

How can i Transpose INSERT statement

Currently when insert my data in a table looks like this.

enter image description here

But I want to Insert as follows

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


I have the following code to Insert data from one database to another(
Mysql
)table

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

Answer

Please try this way 3 insertion separately where $itemid would be same in all cases:

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