-1
<tr class="targetfields">
<td><input type="text" class="form-control" name="order_id[]" value="<?php echo $row3['id']; ?>"/></td>
<td width="400"><textarea name="desc" class="form-control"><?php echo $item_description; ?></textarea></td>
<td><input id="quant" class="form-control common quantity" name="quant[]" type="text" value="<?php echo $quantity; ?>"/></td>
<td><input id="unit_price" class="form-control common price" name="unit_price[]" type="text" value="<?php echo $unit_price; ?>"/></td>
<td><input id="total" readonly class="form-control total" name="total[]" type="text" value=""/></td>
</tr>
<tr class="targetfields">
<td><input type="text" class="form-control" name="order_id[]" value="<?php echo $row3['id']; ?>"/></td>
<td width="400"><textarea name="desc[]" class="form-control"><?php echo $item_description; ?></textarea></td>
<td><input id="quant" class="form-control common quantity" name="quant[]" type="text" value="<?php echo $quantity; ?>"/></td>
<td><input id="unit_price" class="form-control common price" name="unit_price[]" type="text" value="<?php echo $unit_price; ?>"/></td>
<td><input id="total" readonly class="form-control total" name="total[]" type="text" value=""/></td>
</tr>
<tr class="targetfields">
<td><input type="text" class="form-control" name="order_id[]" value="<?php echo $row3['id']; ?>"/></td>
<td width="400"><textarea name="desc[]" class="form-control"><?php echo $item_description; ?></textarea></td>
<td><input id="quant" class="form-control common quantity" name="quant[]" type="text" value="<?php echo $quantity; ?>"/></td>
<td><input id="unit_price" class="form-control common price" name="unit_price[]" type="text" value="<?php echo $unit_price; ?>"/></td>
<td><input id="total" readonly class="form-control total" name="total[]" type="text" value=""/></td>
</tr>
<button id='btn' name='btn' class="btnn primary-btn" type='submit'>Submit</button>
私はこの複数の行を1つのクエリに挿入するにはどうすればよいですか?
PHPなどの合計10行を持って
if(isset($_POST['btn'])){
ob_start();
$order_id = $_POST["order_id"];
$desc = $_POST["desc"];
$quant = $_POST["quant"];
$unit_price = $_POST["unit_price"];
$total = $_POST["total"];
$query = mysqli_query($con,"insert into orders (id,description,quantity,unit_price,total) values('".$order_id."','".$desc."','".$quant."','".$unit_price."','".$total."') ");
私は私は1つのクエリによって、データベース内のすべての行を挿入することができますどのように1 querywにデータベース内のすべてのレコードを挿入しようとしています?あなたがループ
if(isset($_POST['btn'])){
ob_start();
foreach($_POST["order_id"] as $key =>$value){
$order_id = $value;
$desc = $_POST["desc"][$key];
$quant = $_POST["quant"][$key];
$unit_price = $_POST["unit_price"][$key];
$total = $_POST["total"][$key];
$query = mysqli_query($con,"insert into orders (id,description,quantity,unit_price,total) values('".$order_id."','".$desc."','".$quant."','".$unit_price."','".$total."') ");
}
}
を使用してそれを実行したい場合は
を使用することができます。 ..)、(val1、val2 ...) '。 –
ループや配列による方法はありますか? –
ループは良い考えではありません。 SougataBoseは正しい方法を提案しました –