我想通过+ =更改单元格值然后更新它。但程序添加此值并创建一个新行,我只需添加到当前。
`
while (($row = fgetcsv($handle, 100, ',')) !== false) {
$wareHouse = Warehouse::find()->all();
$products = Products::find()->all();
$createBoth = true;
foreach ($wareHouse as $wr)
{
foreach ($products as $prod)
{
if ($prod->product_name==$row[0]&&$prod->warehouse_id==$wr->id&&$wr->warehouse_name==$row[2]){
$prod->qty+=$row[1];
$prod->update();
$createBoth=false;
}
}
}
`
答案 0 :(得分:1)
你可以试试这个;
while (($row = fgetcsv($handle, 100, ',')) !== false) {
$wareHouse = Warehouse::find()->all();
$createBoth = true;
foreach ($wareHouse as $wr) {
if ($wr->warehouse_name == $row[2]):
$prod = Products::find(['product_name' => $row[0], 'warehouse_id' => $wr->id])->one();
$prod->qty = $prod->qty + $row[1];
$prod->update();
$createBoth = false;
endif;
}
}