[英]How to insert dynamic input values into the database using codeigniter?
数据在数据库图像中给出的同一列中写入数据库(参考图像: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
值插入到单个表列中,您可以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
);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.