次の値を持つ入力行があります (例として、2 行のみを表示しますが、さらに多くの行が存在する可能性があります。もちろん、値は異なる場合があります)
entry_id | transaction_partner_name | registration_number
values
10 name 1 number 1
11 name 2 number 2
mysql テーブルを値で更新する必要があります
クエリは次のようになります
UPDATE 2_1_transactionpartners SET
CompanyName = CASE NumberRenamed
WHEN ? THEN ? WHEN ? THEN ?
END,
RegistrationNumber = CASE NumberRenamed
WHEN ? THEN ? WHEN ? THEN ?
END
WHERE NumberRenamed in (?,?)
また
$sql = "
UPDATE 2_1_transactionpartners SET
CompanyName = CASE NumberRenamed
$when_then
END,
RegistrationNumber = CASE NumberRenamed
$when_then
END
WHERE NumberRenamed in ($placeholders_for_number_renamed)";
foreach内で変数を作成します
$entry_id_for_number_renamed = array();
foreach ($_POST['entry_id'] as $i => $entry_id) {
$for_company_name .= ( $_POST['entry_id'][$i]. ','. $_POST['transaction_partner_name'][$i]. ',' );
$for_registration_number .= ( $_POST['entry_id'][$i]. ','. $_POST['registration_number'][$i]. ',' );
$entry_id_for_number_renamed[] = $_POST['entry_id'][$i];
$when_then .= 'WHEN ? THEN ? ';
$placeholders_for_number_renamed .= '?,';
}
$for_company_name = rtrim($for_company_name, ',');
$for_company_name = explode(',', $for_company_name);
$for_registration_number = rtrim($for_registration_number, ',');
$for_registration_number = explode(',', $for_registration_number);
$insertData = array_merge( $for_company_name, $for_registration_number, $entry_id_for_number_renamed );
より良い(より短い)解決策についてのアイデアがあれば、アドバイスをお願いします