将多个选择值从html插入到mysql db中

I have application where user can select multiple items from html selet and this selection need store as one id row,

Ex :

time_id   time_name   values

1         common     x,y,z

Below is my PHP controller,

$time_data=array(
    'time_name'=>$this->input->post('time_name'),
    'time_days'=>$this->input->post('time_days'),
    'time_hours'=>$this->input->post('time_hours'),
    'time_minutes'=>$this->input->post('time_minutes'),
    'time_start'=> implode(",", $this->input->post('time_start')),
    'time_end'=>implode(",", $this->input->post('time_end')),
    'time_department'=>implode(",", $this->input->post('time_department')),
    'time_timecategory'=>$this->input->post('time_timecategory'),
    'time_searchwords'=>$this->input->post('time_searchwords'),
    'timecreated_time' =>date("Y-m-d H:i:s")
    );

//Add starts
if($this->form_validation->run() !== FALSE) {
    $result = $this->model_admin->updatetime($time_data);

    if(!$result) {
        $content = $this->model_admin->LastEntrytime();
        echo json_encode($content);
    }
}
else {
    echo json_encode(array('cival'=>0, 'val_message' => validation_errors()));
}

Below is my HTML where user can select multiple items from dropdown,

<div class="col-md-9">
  <select id="time_department" name="time_department[]" class="form-control select2" multiple>
<?php
  foreach($departments_array as $department) { ?>
    <option value="<?php echo $department["department_id"];?>"><?php echo $department["department_name"]?></option>
<?php
  } ?>
  </select>
</div>

With this my multiselected values are stored as x,y,z or 1,2,4 etc...

But i want to create many-to-many linked table in which i will store values of x,y,z in each different row instead of comma seperated values,

How can i insert multiple selected values in mysql as many to many table?

Thanks,

Not sure if I quite understood your problem. See if this helps:

1) First of all, create a new table to store the values that will contain the values selected.

2) What is the primary key of this table? Is it time_id? If it doesn't have a PK, then create one.

3) In the new table you just created, add a foreign key that references the primary key of the first existing table. Also make that field/column not null.

4) Add as many rows as necessary (according to how many values are selected) in the just created table. Don't forget to link them back to the correct row in the first table using the FK.

Is that what you were trying to achieve?