我试图建立学生成绩管理系统。当我试图根据每个学生在考试中的总成绩而给每个学生分配职位时,我会遇到问题。在我的输出中,我得到第1个(获得标记448),第2个(获得标记444),第3个(获得标记445),第4个(获得标记447),第15个(获得标记450),第8个(获得标记449),但是我没有在我的代码中找不到任何问题。它应该是第一个(获得标记450),第二个(获得标记449)。
if (!function_exists('get_student_position')) {
function get_student_position($school_id, $academic_year_id, $class_id, $student_id, $section_id = null) {
$condition = " academic_year_id = $academic_year_id ";
$condition .= " AND school_id = $school_id";
$condition .= " AND class_id = $class_id";
$condition .= " AND student_id = $student_id";
if($section_id){
$condition .= " AND section_id = $section_id";
}
$ci = & get_instance();
$sql = "SELECT id, avg_grade_point, FIND_IN_SET( (avg_grade_point+total_obtain_mark),
( SELECT GROUP_CONCAT( (avg_grade_point+total_obtain_mark) ORDER BY avg_grade_point DESC )
FROM final_results ) ) AS rank
FROM final_results
WHERE $condition";
$result = $ci->db->query($sql)->row();
$rank = '';
if(!empty($result)){
$rank = $result->rank;
}
if($rank == 1){
return $rank.'st';
}elseif($rank == 2){
return $rank.'nd';
}elseif($rank == 3){
return $rank.'rd';
}elseif($rank > 3 ){
return $rank.'th';
}else{
return '--';
}
}
}