lundi 28 septembre 2015

fetch data from mysql by multiple checkbox with different names.(array) Codeigniter

I want to fetch data from a database with multiple check box name arrays but I'm having an issue that it only returns the first selected check box on the name arrays and returns nothing when having different combinations of selections. Please help me. Thank you.

HERE IS MY VIEW:

<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>

HERE IS MY MODEL:

$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();




Aucun commentaire:

Enregistrer un commentaire