gpt4 book ai didi

php - 批处理未插入到表中

转载 作者:行者123 更新时间:2023-11-30 21:25:43 25 4
gpt4 key购买 nike

我有以下表格用于存储元素的购买和发行。

store_update_stock 表

+-----------------+----------+-------------------+-----------------+--------+
| update_stock_id | supplier | user order_status | transfer_status | status |
+-----------------+----------+-------------------+-----------------+--------+

store_update_stock_details 表

+-------------------------+-----------------+------+-----+------------+--------+
| update+stock_details_id | update_stock_id | item | qty | unit_price | status |
+-------------------------+-----------------+------+-----+------------+--------+

02) 我对项目和文件使用了 Codeigniter,如下所示:

Controller

public function verifyItemReqFromHD()       
{
$this->checkPermissions('edit', 'issueApprovedItem');
$bc = array(array('link' => '#', 'page' => 'Item Request From HD'));
$meta = array('page_title' => 'Item Request From HD', 'bc' => $bc);
$this->data['products'] = $this->Item_model->getProducts();

if ($this->form_validation->run() == true) {

$count = count($this->input->post('item'));
$items = $this->input->post('item');
$qts = $this->input->post('qty');
$up = $this->input->post('unit_price');
$total = 0;
for ($x = 0; $x < $count; $x++) {
$details[$x]['update_stock_id'] = null;
$details[$x]['item'] = $items[$x];
$details[$x]['qty'] = $qts[$x];
$details[$x]['unit_price'] = $up[$x];
$details[$x]['status'] = 1;
}

$stock = array(
'supplier' => $this->session->userdata('id_user'),
'user' => ucfirst($this->session->userdata('name')),
'order_status' => 'verifyIssue',
'transfer_status' => 'Verified',
'status' => '1'
);
if ($this->Item_model->addItemReqFromHD($stock, $details)) {
$this->session->set_flashdata('message', 'Successfully Sent Your Request..!!');
redirect('item/verifyItemReqFromHD');
}

} else {
$this->session->set_flashdata('error', validation_errors());
$this->render('item/viewItemtoIssued', $meta, $this->data);
}
}

型号

function addItemReqFromHD($data,$details)
{
$this->db->trans_start();
if ($this->db->insert('store_update_stock', $data)) {
$id = $this->db->insert_id();
foreach ($details as $detail) {
$detail['update_stock_id'] = $id;
$this->db->insert('store_update_stock_details', $detail);
}
}
$this->db->trans_complete();
if ($this->db->trans_status() === true) {
return true;
}
return false;

}

查看

<?php
if(!empty($issueData)){
$common=$issueData[0];
}
?>

<script type="text/javascript">

$(document).on("change", "#item", function () {

$.ajax({
'url': '<?=site_url("item/isExistProduct/?q=")?>' + $('#item').val(),
'method': 'GET',
'success': function (data) {


var jData = JSON.parse(data);
if (jData.status == true) {

jData.data.forEach(data => {
$('#request_table').append('<tr>' +
'<td ><span id="product" >' + data.item_name + '</span>' +
'<input type="hidden" id="item[]" name="item[]" value="' + data.item_id + '">' +
'</td>' +
'<td class="text-center">' + data.qty + '</td>' +
'<td class="text-center"><input class="form-control text-right" disabled id="sales_price[]" name="sales_price[]" value="' + data.up+ '"></td>' +
'<td class="text-center"><input class="form-control text-center rquantity" data-qty-bal="' + data.qty + '" autofocus required type="number" step="any" id="qty[]" name="qty[]" ></td>' +
'<td class="text-center" ><i class="fa fa-remove remove" style="cursor: pointer"></i></td>' +
'</tr>');
})
}

},
'error': function () {

}
});


});

$(document).on("click", ".remove", function () {
$(this).closest('tr').remove();
});

var old_row_qty;
$(document).on("focus", '.rquantity', function () {
old_row_qty = $(this).val();
}).on("change", '.rquantity', function () {
var row = $(this).closest('tr');
var issue_q = parseFloat($(this).val());
var available_q = parseFloat($(this).data('qty-bal'));

if (issue_q > available_q) {
console.log("ssss");
$(row).addClass('danger');
$('#add_sale').attr('disabled', true);
alert("Can not proceed your request ..!!. Issue quantity is higher than the available quantity..");
} else {
console.log("remove");
$(row).removeClass('danger');
$('#add_sale').attr('disabled', false);

}

});
</script>

<!-- Main content -->
<section class="invoice">
<!-- title row -->
<div class="row">
<div class="col-xs-12">

</div>
<!-- /.col -->
</div>


<!-- Table row -->
<div class="row" style="margin-top: 2%">
<div class="col-xs-12 table-responsive">
<table class="table table-striped">
<thead>
<tr class="" style="background-color: #33ff99 !important;">
<th>Item</th>
<th class="text-right">Requested Qty</th>
<th class="text-right">Approved Qty</th>
</tr>
</thead>
<tbody>
<?php

if (!empty($issueData)) {
foreach ($issueData as $rows){

?>
<tr>
<td style="width: 40%"><?=$rows->item_name?></td>
<td style="width: 15%" class="text-right"><?=$rows->r_qty+0?></td>
<td style="width: 15%" class="text-right"><?=$rows->ap_qty+0?></td>
</tr>
<?php

}
}
?>
</tbody>
</table>


</div>
<!-- /.col -->
</div>
<!-- /.row -->

<form action="<?= site_url('item/verifyItemReqFromHD') ?>" method="post">
<div class="col-md-5">
<div class="form-group"><label>Select Item</label>
<select name="item" id="item" class="form-control select2" required>
<option value="">Select Item</option>
<?php
if (!empty($products)) {
foreach ($products as $row) {

?>

<option value="<?= $row->item_id ?>"><?= $row->item_name ?></option>
<?php
}
}

?>
</select>
</div>
</div>
<div class="col-md-12 column">
<div class="col-md-12">
<div class="control-group table-group">
<label class="table-label">Issue Items *</label>

<div class="controls table-controls">
<table id="request_table"
class="table items table-striped table-bordered table-condensed table-hover">
<thead>
<tr class="" style="background-color: #ff66a3 !important;">
<th class="col-md-5">Item Name</th>
<th class="text-center col-md-2">Available Qty</th>
<th class="text-center col-md-2">Unit Price</th>
<th class="text-center col-md-2">Issuing Qty</th>

</th>
<th class="col-md-2" style="width: 30px !important; text-align: center;">
<i class="fa fa-trash-o" style="opacity:0.5; filter:alpha(opacity=50);"></i>
</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr id="tfoot" class="tfoot active">
<th colspan="2">Total</th>
<th class="text-right"></th>
<th class="text-center">0</th>

<th class="text-center"><i class="fa fa-trash-o"
style="opacity:0.5; filter:alpha(opacity=50);"></i>
</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" id="add_sale" class="btn btn-primary btn-block">Issue</button>
</div>
</div>
</form>
</section>

期望的输出

03) 然后我需要使用上面的代码将数据插入到两个表中。

当在 View 中按下“问题”按钮时,相关值没有插入到表中。可能出了什么问题?谁能帮我 ?

最佳答案

尝试$this->db->trans_commit()

关于php - 批处理未插入到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59171869/

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