如何在Codeigniter中插入多个发票值 [英] How to insert multiple invoice values in codeigniter

查看:47
本文介绍了如何在Codeigniter中插入多个发票值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在codeigniter中具有以下布局的表单:

I have a form with below layout in codeigniter:

<input type="text" name="product">`<input type="text" name="cost">`

表单有几行具有相同的输入名称。尝试了一些建议,例如批次创建此线程在这里但无法解决

The form has several rows with the same input names. Have tried several suggestions such as Batch creation and this thread here but not working out

推荐答案

使用相同文本框名称的数组进行批量插入

Use array of same textboxes name for batch insert

insert_batch 函数一次将多个数据插入表中的代码中

insert_batch function insert multiple data at a time to table in codeigniter

查看页面

<form action="<?=base_url('Test_c/insert_data')?>" method="post">
            <div class="col-sm-12">
                <input type="text" name="product[]"><input type="text" name="cost[]">
            </div>
            <div class="col-sm-12">
                <input type="text" name="product[]"><input type="text" name="cost[]">
            </div>
            <div class="col-sm-12">
                <input type="text" name="product[]"><input type="text" name="cost[]">
            </div>
            <div class="col-sm-12">
                <input type="text" name="product[]"><input type="text" name="cost[]">
            </div>
            <div class="col-sm-12">
                <input type="text" name="product[]"><input type="text" name="cost[]">
            </div>
            <input type="submit" name="submit" value="submit">
        </form>

控制器功能

function insert_data() {
            $product = $this->input->post('product');
            $cost = $this->input->post('cost');
            $insert_array = array();
            for ($i=0; $i < count($product); $i++) {
                $tmp = array();
                $tmp['product'] = $product[$i];
                $tmp['cost'] = $cost[$i];
                $insert_array[] = $tmp;
            }

            $this->db->insert_batch('test', $insert_array);
            //echo $this->db->last_query();
    }

这篇关于如何在Codeigniter中插入多个发票值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆