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.' '.$v_student->student_name.' ('.$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.' '.$v_student_info->student_name.' ('.$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 ?