【发布时间】:2015-05-03 13:17:54
【问题描述】:
我有一个应用程序,用户可以从 html selet 中选择多个项目,并且此选择需要存储为一个 id 行,
例如:
time_id time_name values
1 common x,y,z
下面是我的 PHP 控制器,
$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()));
}
下面是我的 HTML,用户可以从下拉列表中选择多个项目,
<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>
这样,我的多选值存储为 x、y、z 或 1、2、4 等...
但我想创建多对多链接表,我将在每个不同行中存储 x、y、z 的值,而不是逗号分隔值,
如何在mysql中插入多个选定的值作为多对多表?
谢谢,
【问题讨论】:
标签: php html mysql codeigniter