我想对每个学生的学生出勤率百分比进行计算,并且会显示属于每个学生的每个出勤率百分比。下面是我的代码:在php中计算mysql mysql
<tbody>
<?php
$data = "SELECT SUM(studAtt_endTime - studAtt_startTime) FROM studentAttendance";
$result = $conn->query($data)
or die ("Error: ".mysqli_error($conn)); //look if theres any error
while($ser2=mysqli_fetch_array($result)) {
?>
<?php
$counter = 1;
$data = "SELECT * FROM student INNER JOIN studentAttendance ON student.stud_matric=studentAttendance.student_stud_matric
INNER JOIN course ON course.course_code=studentAttendance.course_course_code
WHERE course_course_code LIKE '%$_GET[course]%'
GROUP BY student_stud_matric";
$result = $conn->query($data)
or die ("Error: ".mysqli_error($conn)); //look if theres any error
while($ser=mysqli_fetch_array($result)) {
?>
<tr>
<td><center><?php echo $counter;
$counter++; ?></center></td>
<td><?php echo $ser["stud_matric"];?></td>
<td><?php echo $ser["stud_name"];?></td>
<td><?php
$a = $ser["course_contacthour"];
$b = "14";
$tch = ($a * 2) * $b; // tch= total contact hour in 14 week
echo number_format($ser2["SUM(studAtt_endTime - studAtt_startTime)"]/$tch * 100, 2);?></td>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
的问题是,这个代码将总结所有的学生出席率,它会显示每个学生相同的百分比,而不是对学生本身的百分比。
你有一个使用'$ result'的嵌套sl查询 - 这也会被外部查询使用,这可能会导致问题。 – RamRaider
还有其他问题。为什么两个查询? YOu错过了第二个查询中参数名称的引号(即:''%$ _ GET [course]%''应该是''%{$ _ GET ['course']}%'','number_format($ ser2 [“SUM(studAtt_endTime - studAtt_startTime)”]/$ tch * 100,2)'?? – RamRaider
我有两个查询,因为它不能通过一个查询来完成,或者它不能写出正确的查询 'number_format $ ser2 [“SUM(studAtt_endTime - studAtt_startTime)”]/$ tch * 100,2)'是学生考勤百分比的计算 因此,我需要第一个查询中的SUM(studAtt_endTime - studAtt_startTime)' ,所显示的结果是从所有学生的总和'SUM(studAtt_endTime - studAtt_startTime)'计算出来的,而不是像我想要的每个特定学生。@RamRaider –