我很难获取班级部分的所有在读学生
我正在尝试使用ajax获取每节的学生人数,以确定是否达到了学生人数,或者我们可以像上图那样调整座位数。
这是我的JavaScript
<script type="text/javascript">
$(document).ready(function () {
var section_id_post = '<?php echo $student['section_id']; ?>';
var class_id_post = '<?php echo $student['class_id']; ?>';
populateSection(section_id_post, class_id_post);
function populateSection(section_id_post, class_id_post) {
$('#section_id').html("");
var base_url = '<?php echo base_url() ?>';
var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
$.ajax({
type: "GET",
url: base_url + "sections/getByClass",
data: {'class_id': class_id_post},
dataType: "json",
success: function (data) {
$.each(data, function (i, obj)
{
var select = "";
if (section_id_post == obj.section_id) {
var select = "selected=selected";
}
div_data += "<option value=" + obj.section_id + " " + select + ">" + obj.section + "</option>";
});
$('#section_id').append(div_data);
}
});
}
$(document).on('change', '#class_id', function (e) {
$('#section_id').html("");
var class_id = $(this).val();
var base_url = '<?php echo base_url() ?>';
var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
$.ajax({
type: "GET",
url: base_url + "sections/getByClass",
data: {'class_id': class_id},
dataType: "json",
success: function (data) {
$.each(data, function (i, obj)
{
div_data += "<option value=" + obj.section_id + ">" + obj.section + "</option>";
});
$('#section_id').append(div_data);
}
});
});
var date_format = '<?php echo $result = strtr($this->customlib->getSchoolDateFormat(), ['d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy',]) ?>';
$('#dob,#admission_date').datepicker({
format: date_format,
autoclose: true
});
});
这是我的观点
<div class="col-md-3">
<div class="form-group">
<label>Select Section</label>
<select id="section_id" name="section_id" class="form-control" >
<option value="">Select</option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group"><label>Number of Students</label>
<input id="noStd" name="noStd" class="form-control" readonly="readonly"/>
</div>
</div>
我的控制
function numberOfStd() {
$section_id = $this->section_model->get('section_id');
foreach ($section_id as $key => $value) {
if ($value["id"] != 0) {
$count_student[$value["section"]] = $this->studentsession_model->countStudentBySessionBySection($value["id"]);
}
}
$data["count_student_section"] = $count_student;
}
我的模特
public function countStudentBySessionBySection($id){
$query = $this->db->select("*")->join("students", "students.id = student_session.student_id")->where("student_session.section_id", $id)->get("student_session");
return $query->num_rows();
}