douji9184
2017-08-15 04:04
浏览 34

如何在codeigniter中传递<select>的onchange事件的多个值

I want to show student from selected school, class and section. if I delete 'class_id' => $class_id, 'section_id' => $section_id, from controller then it show all student from selected school otherwise it show nothing. any solution please. where am wrong ? This is file from where I have to select value

    <div class="form-group">
                        <label class="col-sm-3 control-label" >School<span class="required">*</span></label>
                                           <div class="col-sm-5">
                                               <select name="school_id" id="school_id" class="js-example-basic-multiple form-control" onchange="get_student_by_school_class_section_id()">
                                            <option value="" >Select School...</option>                                  
                                            <?php if (!empty($all_school_info)): foreach ($all_school_info as $v_school): ?>
                                                    <option value="<?php echo $v_school->school_id; ?>"
                                                    <?php if (!empty($all_student_complain_info->school_id)) {
                                                         echo $v_school->school_id == $all_student_complain_info->school_id ? 'selected ' : ''; } ?>>

                                                                <?php echo $v_school->school_name ; ?>
                                                    </option>
                                                    <?php
                                                endforeach;
                                            endif;
                                            ?> 
                                        </select>  
                                            </div>
                                            </div>      

                                        <div class="form-group">
                        <label class="col-sm-3 control-label" >Class<span class="required">*</span></label>
                                           <div class="col-sm-5">
                                               <select name="class_id" id="class_id" class="js-example-basic-multiple form-control" onchange="get_student_by_school_class_section_id()">
                                            <option value="" >Select Class...</option>                                  
                                            <?php if (!empty($all_classes_info)): foreach ($all_classes_info as $v_class): ?>
                                                    <option value="<?php echo $v_class->class_id; ?>"
                                                    <?php if (!empty($all_student_complain_info->class_id)) {
                                                         echo $v_class->class_id == $all_student_complain_info->class_id ? 'selected ' : ''; } ?>>

                                                                <?php echo $v_class->classes_name ; ?>
                                                    </option>
                                                    <?php
                                                endforeach;
                                            endif;
                                            ?> 
                                        </select>  
                                            </div>
                                            </div>

                                            <div class="form-group">
                        <label class="col-sm-3 control-label" >Section<span class="required">*</span></label>
                                           <div class="col-sm-5">
                                               <select name="section_id" id="section_id" class="js-example-basic-multiple form-control" onchange="get_student_by_school_class_section_id()">
                                            <option value="" >Select Section...</option>                                  
                                            <?php if (!empty($all_section_info)): foreach ($all_section_info as $v_section): ?>
                                                    <option value="<?php echo $v_section->section_id; ?>"
                                                    <?php if (!empty($all_student_complain_info->section_id)) {
                                                         echo $v_section->section_id == $all_student_complain_info->section_id ? 'selected ' : ''; } ?>>

                                                                <?php echo $v_section->section_name ; ?>
                                                    </option>
                                                    <?php
                                                endforeach;
                                            endif;
                                            ?> 
                                        </select>  
                                            </div>
                                            </div>
<div class="form-group">
                <label class="col-sm-3 control-label" >Student<span class="required">*</span></label>
                                   <div class="col-sm-5">
                                       <select name="student_id" id="student" class="js-example-basic-multiple form-control" >
                                    <option value="" >Select Student...</option>                                  
                                    <?php if (!empty($student_info)): foreach ($student_info as $v_student): ?>
                                            <option value="<?php echo $v_student->student_id; ?>"
                                            <?php if (!empty($all_student_complain_info->student_id)) {
                                                 echo $v_student->student_id == $all_student_complain_info->student_id ? 'selected ' : ''; } ?>>

                                                        <?php echo $v_student->student_id.'&nbsp;&nbsp;'.$v_student->student_name.'&nbsp;('.$v_student->student_father_name.')' ; ?>
                                            </option>
                                            <?php
                                        endforeach;
                                    endif;
                                    ?> 
                                </select>  
                                    </div>
                                    </div>

This is ajax.php

function get_student_by_school_class_section_id() {
     var school_id = document.getElementById('school_id').value;
     var class_id = document.getElementById('class_id').value;
     var section_id = document.getElementById('section_id').value;
        var base_url = '<?= base_url() ?>';
        var strURL = base_url + "admin/global_controller/get_student_by_school_class_section_id/" + school_id + "/" + class_id + "/" + section_id;
        var req = getXMLHTTP();
        if (req) {
            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {
                        var result = req.responseText;

                        $("#student").html("<option value='' >Select Student...</option>");
                        $("#student").append(result);

                    } else {
                        alert("There was a problem while using XMLHTTP:
" + req.statusText);
                    }
                }
            }
            req.open("POST", strURL, true);
            req.send(null);
        }

    }

this is controller.php

public function get_student_by_school_class_section_id($school_id, $class_id, $section_id) {
        $HTML = NULL;
        $this->studentrecord_model->_table_name = 'tbl_studentrecords';
        $this->studentrecord_model->_order_by = 'student_id';
        $student_info = $this->studentrecord_model->get_by(array('school_id' => $school_id, 'class_id' => $class_id, 'section_id' => $section_id, 'status' => '1'), FALSE);
        if (!empty($student_info)) {
            foreach ($student_info as $v_student_info) {
                $HTML.="<option value='" . $v_student_info->student_id . "'>" .$v_student_info->student_id.'&nbsp;'.$v_student_info->student_name.'&nbsp;('.$v_student_info->student_father_name.')'. "</option>";
            }
        }
        echo $HTML;
    }

I want to show student from selected school, class and section. if I delete 'class_id' => $class_id, 'section_id' => $section_id, from controller then it show all student from selected school otherwise it show nothing. any solution please. where am wrong ?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxing7083 2017-08-15 07:00
    已采纳

    I have done by changing global_controller.php code like this

    public function get_student_by_school_class_section_id($school_id, $class_id, $section_id) {
            $HTML = NULL;
            $school = $school_id;
            $class = $class_id;
            $section = $section_id;
            $this->studentrecord_model->_table_name = 'tbl_studentrecords';
            $this->studentrecord_model->_order_by = 'student_id';
            $student_info = $this->studentrecord_model->get_by(array('school_id' => $school, 'class_id' => $class, 'section_id' => $section, 'status' => '1'), FALSE);
            if (!empty($student_info)) {
                foreach ($student_info as $v_student_info) {
                    $HTML.="<option value='" . $v_student_info->student_id . "'>" .$v_student_info->student_id.'&nbsp;'.$v_student_info->student_name.'&nbsp;('.$v_student_info->student_father_name.')'. "</option>";
                }
            }
            echo $HTML;
        }
    
    打赏 评论
  • douxingti9307 2017-08-15 04:41

    this is studentrecord_model.php

    public function all_student_record_info_by_scs($school_id, $class_id, $section_id) {
            $this->db->select('tbl_studentrecords.*', FALSE);
            $this->db->select('tbl_school.*', FALSE);
            $this->db->select('tbl_class.*', FALSE);
            $this->db->select('tbl_section.*', FALSE);
            $this->db->select('tbl_fee_department.*', FALSE);
            $this->db->from('tbl_studentrecords');
            $this->db->join('tbl_school', 'tbl_school.school_id = tbl_studentrecords.school_id', 'left');
            $this->db->join('tbl_class', 'tbl_class.class_id = tbl_studentrecords.class_id', 'left');
            $this->db->join('tbl_section', 'tbl_section.section_id = tbl_studentrecords.section_id', 'left');
            $this->db->join('tbl_fee_department', 'tbl_fee_department.fee_department_id = tbl_studentrecords.fee_department_id', 'left');
            $this->db->where('tbl_studentrecords.school_id', $school_id);
            $this->db->where('tbl_studentrecords.class_id', $class_id);
            $this->db->where('tbl_studentrecords.section_id', $section_id);
            $query_result = $this->db->get();
            $result = $query_result->result();
            return $result;
        }
    
    打赏 评论

相关推荐 更多相似问题