我想从具有多个复选框名称数组的数据库中获取数据,但是我遇到的问题是它只返回名称数组上的第一个选中的复选框,并且在选择不同的组合时不返回任何内容。请帮我。
这是我的观点:
<div class="col-lg-3">
<div class="form-group">
<label>Year Level</label>
<?php if($cat_yr_lvl !== false): ?>
<?php foreach($cat_yr_lvl as $data): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="yr_lvl[]" value="<?php echo $data->year_level?>"><?php echo $data->year_level?>
</label>
</div>
<?php endforeach;?>
<?php endif; ?>
</div>
</div>
<div class="col-lg-3">
<div class="form-group">
<label>Semester</label>
<?php if($cat_sem !== false): ?>
<?php foreach($cat_sem as $data): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="sem[]" value="<?php echo $data->sem?>"><?php echo $data->sem?>
</label>
</div>
<?php endforeach;?>
<?php endif; ?>
<hr>
<label>Gender</label>
<?php if($cat_gender !== false): ?>
<?php foreach($cat_gender as $data): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="gender[]" value="<?php echo $data->gender?>"><?php echo $data->gender?>
</label>
</div>
<?php endforeach;?>
<?php endif; ?>
</div>
</div>
<div class="col-lg-3">
<div class="form-group">
<label>Midterm Grade Description</label>
<?php if($cat_mid !== false): ?>
<?php foreach($cat_mid as $data): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="mid[]" value="<?php echo $data->mid?>"><?php echo $data->mid?>
</label>
</div>
<?php endforeach;?>
<?php endif; ?>
<hr>
<label>Final Grade Description</label>
<?php if($cat_final !== false): ?>
<?php foreach($cat_final as $data): ?>
<div class="checkbox">
<label>
<input type="checkbox" name="final[]" value="<?php echo $data->fin?>"><?php echo $data->fin?>
</label>
</div>
<?php endforeach;?>
<?php endif; ?>
</div>
</div>
这是我的模特:
$student_db = $this->load->database('student_db', TRUE);
$str_dept = implode(",",$this->input->get('dept_id'));
$str_sy = implode(",",$this->input->get('sy'));
$str_yr_lvl = implode(",",$this->input->get('yr_lvl'));
$str_sem = implode(",",$this->input->get('sem'));
$str_gender = implode(",",$this->input->get('gender'));
$str_mid = implode(",",$this->input->get('mid'));
$str_final = implode(",",$this->input->get('final'));
$student_db->select('*');
$student_db->where_in('Department_College_dept_id', $str_dept);
$student_db->where_in('Student_sy', $str_sy);
$student_db->where_in('Student_year_level', $str_yr_lvl);
$student_db->where_in('Student_sem', $str_sem);
$student_db->where_in('gender', $str_gender);
$student_db->where_in('midterm_description', $str_mid);
$student_db->where_in('final_description', $str_final);
$query = $student_db->get('std_v');
return $query->result();
答案 0 :(得分:0)
where_in必须是数组的第二个参数。
在将参数传递给where_in之前不要使用implode。
例如:替换此
$str_dept = implode(",",$this->input->get('dept_id'));
通过
$str_dept = $this->input->get('dept_id');
其他参数相同。
同时确保$ this-&gt; input-&gt; get('dept_id')是否为数组。
它必须是一个数组,因为它在where_in。
中用作第二个参数要检查$ this-&gt; input-&gt; get('dept_id')是否为数组,请使用以下命令:
echo '<pre>'; print_r($this->input->get('dept_id')); exit;
要检查上次执行的查询,请在模型中使用以下代码:
echo $this->db->last_query(); exit;