如何使用 codeigniter 将动态输入值插入数据库?

How to insert dynamic input values into the database using codeigniter?

我有动态输入数据,我想存储项目名称(参考image:1)

将数据放入数据库中的同一列中,就像数据库图像中给出的一样(参考 image:2)。

我如何在 codeigniter 中做到这一点?

我想存储 item_name 列中给出的项目名称的动态输入数据。

<?php 
 Class my_controller extends CI_controller{         
   public function my_method(){
    $data = array(
    'total_price' => $this->input->post('total_price'), //Total price of all item
    'item_name' => $this->input->post('item_name') //Dynamic input value of item name
);
$result = $this->my_model->inser_item($data);
}
 }
?>

<div>
<form action="<?php echo base_url(); ?>my_controller/my_method" method="post">
<input type="text" name="item_name[]" id="item_name">
<input type="text" name="total_price" id="total_price">

<button type="submit" name="submit">Submit</button>
</form>
</div>

提前致谢。

我不知道我是否理解正确,如果您想将 item_name 值插入单个 table 列,您可以 implode() 它:

...
$data = array(
    'total_price' => $this->input->post('total_price'), //Total price of all item
    'item_name' => implode(',', $this->input->post('item_name')) //Dynamic input value of item name
);
...