0

i have applied tags functionality in my project just like stack overflow.

When i subit multiple tags from my form, and in my controller i am getting it like this:

$this->input->post('tags_id') so i am getting 2,3,44,442 as the value for $this->input->post('tags_id') altogether.

What i want is i want the each value to be inserted into my tags table one by one.

How can i get the each value from from the comma separated list to be inserted in my db? Please help me...

I am doing the following to insert into my db

  function entry_insert_instdetails()
{ 
   $this->load->database();     
   $this->db->trans_begin();  
   $data=array('instrunction'=> $this->input->post('tags_id'),   
   'creater_id'=>$this->session->userdata('userid'), 
    ); 
    $this->db->insert('instructions',$data); 

  if ($this->db->trans_status() === FALSE)
    {
        $this->db->trans_rollback();
    }  
  else 
    {
        $this->db->trans_commit();
    }
}
1
  • 6
    check the explode function. splits a string into an array. str_getcsv does the same for comma seperated values (csv) with some special functions. Commented May 8, 2013 at 6:20

1 Answer 1

2

You can do it easily with explode function of php

$data   =   array('instrunction'=> $this->input->post('tags_id');

$ids    =   explode(',',$data);

unset($data);

foreach($ids as $id)
{
    $data['tag_id'] =   $id;    // tag_id is table column
    $this->db->insert('instructions',$data);
    unset($data);
}
Sign up to request clarification or add additional context in comments.

Comments

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.