douji9184 2017-08-15 04:04
浏览 35
已采纳

如何在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;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀