0
foreachループの内部にすべてのレコードを表示するテーブルを作成しました。次に、選択して1つの配列値を更新してSQL更新を追加しました。別の値を選択すると、ループはテーブル内のすべてのレコードを更新します。私は一日中それで苦労していた、助けてください。PDO update foreachループ内の行の値
foreachが間違っている場合は、レコードを表示して各アレイの更新を許可するテーブルを表示する方法を提案していただき、ありがとうございます。
<?php
foreach ($stmt as $key => $row)
{
$newcustomerid = htmlentities($row['customer_id']);
echo '<tr><td>' . htmlentities($row['customer_company']) . '</td>';
echo '<td> id:' . $newcustomerid . 'key: ' . $key .'</td>';
echo '<td>' . htmlentities($row['customer_email']) . '</td>';
echo '<td>' . htmlentities($row['customer_phone']) . '</td>';
echo '<td>' . htmlentities($row['customer_country']) . '</td>';
echo '<td>' . htmlentities($row['customer_city']) . '</td>';
echo '<td>' . htmlentities($row['customer_segment']) . '</td>';
echo '<td>' . htmlentities($row['customer_updated']) . '</td>';
$customer_status = htmlentities($row['customer_status']);
if(isset($_POST['Submitbb'])){ //check if form was submitted
$input = $_POST['Submitbb']; //get input text
$stmtUpdateStatus = $conn->prepare("UPDATE user_customers SET `customer_status` = :customer_status WHERE `customer_id` = :customer_id");
$stmtUpdateStatus->execute(array(':customer_status' => $input, ':customer_id' => $row['customer_id']));
}
echo '<td>
<form action="" method="post">
<select name="Submitbb" onchange="this.form.submit();">
<option> - ' . $customer_status . ' - </option>
<option>Susisiekti</option>
<option>Priminimas 1</option>
<option>Priminimas 2</option>
<option>Paskambinti</option>
<option>Netinkamas klientas</option>
</select>
</form>
</td>';
echo '<td>' . 'Išsaugoti' . '</td></tr>';
}
?>
ありがとうございます。
はありがとうそれを比較
を更新するデータベース内の行をキャプチャするために隠された入力を使用することができます!しかし、あなたが投稿した2番目のコードブロックの3行目の "未定義インデックス:customer_id"と書いてあります。 – Lukas
ちょっと、両方のブロックの新しいコピーを取っておきます。エラーを修正するためのものを含めていくつか編集しました – andrew
ありがとう、私は今今しようとします。 – Lukas