gpt4 book ai didi

php - MySQL : Table multiple rows Insert into one sql row

转载 作者:行者123 更新时间:2023-11-29 01:50:49 27 4
gpt4 key购买 nike

目前我正在开发一个软件,可以在表格中创建多行。 Purchase Table

但是我编写 PHP 代码的原因是,它会在 SQL 中创建多行,但我需要针对一个发票号创建一行。

Html(使用 ajax 自动生成):

<tr>
<td><input class="form-control" type="text" name="product_name[]" value="'.$proData['name'].'"></td>
<td><input class="form-control qnt'.$proData['id'].'" min="0" step="any" type="number" name="qnt[]" placeholder="Quantity"></td>
<td><input class="form-control unit_price'.$proData['id'].'" type="number" min="0" step="any" name="unit_price[]" placeholder="Unit Price"></td>
<td><input class="form-control pack_size'.$proData['id'].'" type="number" min="0" step="any" name="pack_size[]" placeholder="Pack Size"></td>
<td><input class="form-control unit_pack'.$proData['id'].'" type="number" min="0" step="any" name="unit_pack[]" placeholder="Unit Pack (jar/Drum)"></td>
<td><input class="form-control total_kg'.$proData['id'].'" type="number" name="total_kg[]" placeholder="Total Kg/s" value="" readonly></td>
<td><input class="form-control total_price'.$proData['id'].'" type="number" name="total_price[]" placeholder="Total Price &#2547;" value="" readonly></td>
<td><button type="button" class="rowDelete btn btn-danger"><i class="icon-trash"></i></button></td>
</tr>

PHP 代码:

public function add(){
// Form Inputs
$invoice = $this->input->post('invoice');
$date = $this->input->post('date');
$created_by = $this->input->post('created_by');
$products = $this->input->post('products');
$qnt = $this->input->post('qnt[]');
$unit_price = $this->input->post('unit_price[]');
$pack_size = $this->input->post('pack_size[]');
$unit_pack = $this->input->post('unit_pack[]');
$total_kg = $this->input->post('total_kg[]');
$total_price = $this->input->post('total_price[]');
$payed = $this->input->post('payed');
$price_less = $this->input->post('price_less');
$price_discount = $this->input->post('price_discount');
$price_due = $this->input->post('price_due');
$grand_total = $this->input->post('grand_total');
$payMethod = $this->input->post('payMethod');
$bank_name = $this->input->post('bank_name');
$cheque_no = $this->input->post('cheque_no');
$bank_acc_no = $this->input->post('bank_acc_no');

for($i = 0; $i < count($qnt); $i++){
$purchaseData = array(
'invoice_no' => $invoice,
'date' => $date,
'product_id' => $products,
'create_date' => $created_by,
'qnt' => $qnt[$i],
'unit_price' => $unit_price,
'pack_size' => $pack_size,
'unit_pack' => $unit_pack,
'total_kg' => $total_kg,
'total_price' => $total_price,
'payed' => $payed,
'price_less' => $price_less,
'price_discount' => $price_discount,
'price_due' => $price_due,
'grand_total' => $payMethod,
'payMethod' => $grand_total,
'bank_name' => $bank_name,
'cheque_no' => $cheque_no,
'bank_acc_no' => $bank_acc_no
);

$PurchaseQuery = $this->db->insert('purchase', $purchaseData);

if($PurchaseQuery){
$purchaseAdded = "Product Purchase Add.";
$this->session->set_flashdata('purchaseAdded', $purchaseAdded);
redirect('Purchase');
}
}
}

请帮助。我正在使用 CI。

最佳答案

我退出的要求不同。你能做的是?而不是遍历 items 。我是说

count($qnt)

只是 json_encode() 多个项目

或者改变你的模式并规范化你的表格
将订单和订单项目放在 2 个不同的表中

关于php - MySQL : Table multiple rows Insert into one sql row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44238740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com