请我试图分配类的位置,例如)第一,第二,第三等,在每个类根据谁有最高分时,总分数相加将不胜感激任何帮助The image added is my database
<div>
<?php
$classid;
$studentid;
$term;
$query8= $dbh->prepare("SELECT SUM(Aggregate) AS Aggregate , StudentId FROM tblresult WHERE ClassId=? and Term=? GROUP BY StudentId ORDER BY SUM(Aggregate) DESC");
$query8->execute(array($classid,$term));
//$results8 = $query8-> fetchAll(PDO::FETCH_ASSOC);
$results8 = $query8-> fetchAll(PDO::FETCH_ASSOC);
$i=0;
$u=0;
echo $studentid."<br>";
foreach($results8 as $result8){
$i++;
echo $Sid = $i.'-'.$result8['Aggregate'].'-----'.$Students_id=$result8['StudentId']."<br>";
//$position = array_search($studentid, $Students_id);
}
//$position = array_search($studentid, $Students_id);
//Position: echo $position;
?>
</div>
1条答案
按热度按时间py49o6xq1#
下面我是怎么做的,但是你必须把class_id和student_id作为列表来给予你一个有意义的结果。
我模拟你的db表,结构如下: