【发布时间】:2017-12-14 15:19:23
【问题描述】:
function SubjectPosition($term, $session, $subject, $class, $student_id, $category){
$res = 'results_sec';
$get_position = mysqli_query($mysqli, "SELECT student_id, (SUM(con_ass)+SUM(hwork)+SUM(test)+SUM(exam_score)) AS Total
FROM `$res`
WHERE `class_id` = '$class'
AND `subject_id` = '$subject'
AND `session_id` = '$session'
AND `term_id` = '$term'
GROUP BY student_id
ORDER BY Total DESC") or die(mysqli_error($mysqli));
$post = 1;
$temp_score = 0;
while ($rs = $get_position -> fetch_assoc()){
$stud_id = $rs['student_id'];
$score = $rs['Total'];
if($student_id == $stud_id && $temp_score <> $score){
return $post;
}
else if($student_id == $stud_id && $temp_score == $score){
return $post - 1;
}
$temp_score = $score;
$post = $post + 1;
}
}
假设查询返回
Student_id | Total
-----------------------------------
SID/001 | 701
SID/005 | 702
SID/007 | 702
SID/002 | 702
SID/003 | 655
SID/004 | 639
我有上面的代码,想为结果生成位置。 我希望职位类似于下表
Student_id | Total | Position
----------------------------------------------------
SID/001 | 701 | 1
SID/005 | 702 | 2
SID/007 | 702 | 2
SID/002 | 702 | 2
SID/003 | 655 | 5
SID/004 | 639 | 6
我需要在上面的脚本中更正什么。任何帮助将不胜感激。
【问题讨论】:
-
你只想要学生的位置吗?同样在预期输出中,ID 为 SID/003 的学生是否应该排名第三?
标签: php positioning