1

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.

5
  • post data not an images Commented Jan 19, 2018 at 6:04
  • Need a little more clarity on what you are trying to achieve. Commented Jan 19, 2018 at 6:07
  • Thanks both for the reply..I have dynamic input for item name and a input for total price ..i want to store the data of item name in a same column..like in the image "Database" item_name column. check the image you'll understand.. @abhinav Commented Jan 19, 2018 at 6:14
  • Your code and your images look quite different. In the image, you are having multiple inputs while in the code it looks like you are having just one input. Commented Jan 22, 2018 at 8:35
  • Thanks..I got the answer .@abhinav Commented Jan 22, 2018 at 10:08

1 Answer 1

1

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
);
...
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer Exactly what i was looking for.. @Hasta Dhana. I solved it already

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.