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,