Search code examples
javascriptphpjquerymysqlcodeigniter-2

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


I have dynamic input data and i want to store Item name(Refer image:1) enter image description here

data into the database in the same column like given in the database image (Refer image:2). enter image description here

How do i do that in codeigniter?

I want to store dynamic input data of item name like given in the item_name column.

<?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>

Thanks in advance.


Solution

  • I don't know if I get it correctly, if you want to insert the item_name values into a single table column, you could implode() it :

    ...
    $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
    );
    ...