我有一个包含40名学生和他们的CGPA的表格,我希望系统将3名学生分成一组,系统应该决定哪些学生应该组合(CGPA高、中、低的学生)。最后,我想将每个学生的id插入到一个新的Mysql表中,如何使用PHP实现这一点?
发布于 2022-07-29 07:43:25
SELECT *
FROM students
ORDER BY cgpa DESC;假设您将此查询结果作为$students数组,您可以这样做:
$grouped = [];
$group_count = intdiv(count($students), 3); //calculating number of groups
for($i=0;$i<$group_count;$i++){
//loop group number times
$arr = []; // empty array
$counter = $i;
for($j=0;$j<3;$j++){
//loop student number times in group
array_push($arr, $students[$counter]);//add 3 student that has high, medium and low cgpa to array to create 1 group
$counter+=$group_count;
}
array_push($grouped, $arr);// add created student group to new array
}$grouped是一组学生
https://stackoverflow.com/questions/73162808
复制相似问题