柔晶美网络工作室

柔晶美网络工作室,倾心于web技术的博客站点

关注我 微信公众号

您现在的位置是: 首页 > 博客日记

php分段统计学生成绩的多种方法

2019-11-19 admin php  1873

目前,各中小学统计学生成绩,需要用到分段,比如:三率,以及10-20,20-30...每10分为一段的统计。目前想到的有以下几种方法:

第一种,利用循环递增统计:

int a b c d e =0;
$result=mysql_query(select * from mdl_grade_grades )
while($new_row=mysql_fetch_array($result))
if($new_row['分数字段']>90){
$a++;
} elseif(80<$new_row['分数字段']<90){
$b++;
}elseif.....直接到成绩<60的 为止

第二种,使用array_filter函数筛选数组

//找出大于60小于80的的
$a = array(30,66,90,79,100,22,68,37,60);
$c = 80;
$d = 60;
$t = array_filter($a, function($a) use($c,$d) { return $a>=$d and $a<$c;}); 
得到一数组结果

第三种,用sql语句

select case when finalgrade>='90' then 'A'
when finalgrade>='80' and finalgrade<'90' then 'B'
when finalgrade>='70' and finalgrade<'80' then 'C'
when finalgrade>='60' and finalgrade<'70' then 'D'
when finalgrade<'60' then 'E'
end finalgrade,count(*) from mdl_grade_grades;

到底哪种效率高,暂时没有测试。

文章评论


需要 登录 才能发表评论
热门评论
0条评论

暂时没有评论!