我是codeigniter php developer.so,我需要发送数据库多个复选框值。首先我创建了包含prefer,holiday,facility和accomadation字段的表。
控制器
if($_POST)
{
$prefer= $this->input->post('prefer');
$data['prefer'] = array(
'prefer' => implode(",", $prefer),
);
$holiday= $this->input->post('holiday');
$data = array(
'holiday' => implode(",", $holiday),
);
$facility= $this->input->post('facility');
$data = array(
'facility' => implode(",", $facility),
);
$accommodation= $this->input->post('accommodation');
$data = array(
'accommodation' => implode(",", $accommodation),
);
$this->customize->save_customize_tour_detail($data);
}
视图
狂野&amp;爱冒险的 <div class="checkbox">
<label>
<input type="checkbox" name="prefer[]" value="romantic" />Romantic & sensuous
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="prefer[]" value="healthy" />Healthy & rejuvenating
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="prefer[]" value="fun" />Fun & exciting
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="prefer[]" value="peaceful" />Thought provoking & peaceful
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="prefer[]" value="shopping" />Shopping
</label>
</div></div>
<div style="float:left">
<label for=""><font color="#00CC66">What whould you like to see in a holiday?</font></label>
<div class="checkbox">
<label>
<input type="checkbox" name="holiday[]" value="beach" />Beaches
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="holiday[]" value="wild" />Wild life
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="holiday[]" value="fauna" />Fauna & flora
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="holiday[]" value="archeological" />Archeological sites
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="holiday[]" value="mountains" />Mountains & waterfalls
</label>
</div></div></div>
<br><br><br><br><br><br><br><br><br><br>
<div>
<div style="float:left; margin-right:30px;">
<label for=""><font color="#00CC66">What is the most important facility you need?</font></label>
<div class="checkbox">
<label>
<input type="checkbox" name="facility[]" value="comfortable" />Comfortable accommodation
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="facility[]" value="transportation" />Transportation
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="facility[]" value="guide" />Guide assistance
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="facility[]" value="excellent" />Excellent food
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="facility[]" value="communication" />Communication
</label>
</div></div>
<div style="float:left">
<label for=""><font color="#00CC66">What kind of accommodation pleases you?</font></label>
<div class="checkbox">
<label>
<input type="checkbox" name="accommodation[]" value="standard_duest_house" />Standard Guest Houses
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="accommodation[]" value="three_star" />3 Star Hotels
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="accommodation[]" value="five_star" />5 Star Hotels
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="accommodation[]" value="two_star" />2 Star Hotels
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="accommodation[]" value="four_star" />4 Star Hotels
</label>
</div>
模型
function save_customize_tour_detail($data) {
$this->db->insert('ba_customize_tours',$data);
}
问题是当我点击发送按钮时,只有accomadation值转到table.others(prefer,holoday,facility)值不会出现在表格中。
答案 0 :(得分:3)
试试这段代码:
if($_POST)
{
$prefer= $this->input->post('prefer');
$data['prefer'] =implode(",", $prefer);
$holiday= $this->input->post('holiday');
$data['holiday'] = implode(",", $holiday);
$facility= $this->input->post('facility');
$data['facility'] = implode(",", $facility);
$accommodation= $this->input->post('accommodation');
$data['accommodation'] = implode(",", $accommodation);
$this->customize->save_customize_tour_detail($data);
}