Hi paramvir.
Thank you very much for answering my questions continuously.
Regarding the problem of merge cells, referring to your comment,
When modifying data in merge cells (Worker, Efficiency, C/T, Duty hours 400, Duty hours 600)
Server-side program to update all data of the same group
As a result of coding and executing each of the two types as shown below, an error occurs and the update does not work.
Data is in the form of 5 cd_kinds in the same cd_group.
(cd_kind: 1-Day, 2-Night, 3-Shipment, 4-Etc, 5-Stock)
I'd appreciate it if you could let me know what the problem is.
//update single record in db.
function updateSingle($pdo, $r)
{
$query = "update pp2_month_new set qty_worker = ?, eff_product = ?, cycle_time = ?, qty_not_ot = ?, qty_ot = ?, ";
$total_day = date('t', strtotime($r['mt_product']));
for($j=1; $j<=$total_day; $j++){
$query .= "qty$j = ?, ";
}
$query = substr($query, 0, -2);
$query .= " where id = ?";
$stmt = $pdo->prepare($query);
$result = $stmt->execute(array($r['qty_worker'], $r['eff_product'], $r['cycle_time'], $r['qty_not_ot'], $r['qty_ot'],
$r['qty1'], $r['qty2'], $r['qty3'], $r['qty4'], $r['qty5'], $r['qty6'], $r['qty7'], $r['qty8'], $r['qty9'], $r['qty10'],
$r['qty11'], $r['qty12'], $r['qty13'], $r['qty14'], $r['qty15'], $r['qty16'], $r['qty17'], $r['qty18'], $r['qty19'], $r['qty20'],
$r['qty21'], $r['qty22'], $r['qty23'], $r['qty24'], $r['qty25'], $r['qty26'], $r['qty27'], $r['qty28'], $r['qty29'], $r['qty30'], $r['qty31'],
$r['id']));
if($result == false) {
throw new Exception(print_r($stmt->errorInfo(), 1).PHP_EOL.$query);
}
// Method 1
if($r['cd_kind'] == 0){
$cd_group = $r['cd_group'];
$qty_worker = $r['qty_worker'];
$eff_product = $r['eff_product'];
$cycle_time = $r['cycle_time'];
$qty_not_ot = $r['qty_not_ot'];
$qty_ot = $r['qty_ot'];
}
elseif($r['cd_kind'] == 4){
$query = "update pp2_month_new set qty_worker = '$qty_worker', eff_product = '$eff_product', cycle_time = '$cycle_time', ";
$query .= "qty_not_ot = '$qty_not_ot', qty_ot = '$qty_ot' where cd_group = '$cd_group' and cd_kind > 0";
$result = mysqli_query($conn, $query) or die("Update fail!!");
}
}
//update multiple records in db.
function updateList($updateList)
{
$pdo = getDBH();
foreach($updateList as &$r){
// Method 2
if($r['cd_kind'] == 0){
$qty_worker = $r['qty_worker'];
$eff_product = $r['eff_product'];
$cycle_time = $r['cycle_time'];
$qty_not_ot = $r['qty_not_ot'];
$qty_ot = $r['qty_ot'];
}
else{
$r['qty_worker'] = $qty_worker;
$r['eff_product'] = $eff_product;
$r['cycle_time'] = $cycle_time;
$r['qty_not_ot'] = $qty_not_ot;
$r['qty_ot'] = $qty_ot;
}
updateSingle($pdo, $r);
}
}