我有3张表:
1)出勤
2)登记
3)时间表
1。出勤
sl_no
是注册sl_no
的外键引用,AttID
是主键
2。 registeration
sl_no
是主键
第3。时间表
id
是主键
我正在针对schedule table
和registration table
查询我的数据库,以获取日程安排开始日期,结束日期和学生详细信息where university is same
,如下所示:
<?php
$schedule_query = "SELECT a.scheduleStartDate, a.scheduleEndDate, b.sl_no, b.student_name
FROM schedule a
LEFT JOIN registration b
ON a.university = b.university
WHERE a.scheduleName = 'XYZ Schedule 01'";
$result = mysqli_query($link, $schedule_query);
$row = mysqli_fetch_array($result);
$start = strtotime($row['scheduleStartDate']);
$end = strtotime($row['scheduleEndDate']);
$date = $start;
$attendance_array = array();
?>
我使用以下查询以表格格式显示报告:
<table width="100%" class="tbl" style="font-size: 12px">
<tr>
<th>Sl No</th>
<th>Name</th>
<?php
$ttl = '';
while($date <= $end)
{
$ttl++;
$student_array = array();
$stu_name_td = '';
mysqli_data_seek($result,0);
//Result came from schedule and registration
while($innerrow = mysqli_fetch_array($result)){
$atd_query = "SELECT * FROM attendance WHERE AttDate = '".date('Y-m-d', $date)."' AND sl_no = '".$innerrow['sl_no']."'";
//results from attendance
$present_stu_res = mysqli_query($link, $atd_query);
$attendance_array[$innerrow['student_name']][date('Y-m-d', $date)] = mysqli_num_rows($present_stu_res) > 0 ? 1 : "A";
}
echo "<th>".date('j/m/Y', $date)."</th>";
$date = strtotime("+1 day", $date);
}
?>
<th>Num of Days</th>
<th>Attended</th>
<th>Percentage(%)</th>
</tr>
<?php
$count ='';
foreach($attendance_array as $stu_name=>$innerarray){
$count ++;
?>
<tr>
<td><?php echo $count;?></td>
<td><?php echo $stu_name; ?></td>
<?php
foreach($innerarray as $dateval=>$present_val)
echo '<td>'.$present_val.'</td>';
echo '<td>'.$ttl.'</td>';//Total No of Days
$attended = array_sum($innerarray);
echo '<td>'.$attended.'</td>';//No of Days Attended
$percent_cal = $attended / $ttl;
$percent = number_format( $percent_cal * 100, 2 ) . '%';
echo '<td>'.$percent.'</td>';//Percentage
?>
</tr>
<?php } ?>
<?php }?>
</tr>
</table>
从上面的代码我得到如下输出:
Student Name 17/06/2015 18/06/2015 19/06/2015 20/06/2015 21/06/2015 Num_of_days Attended Percentage(%)
Student1 1 A 1 A 1 6 3 60%
Student2 1 A 1 A 1 6 3 60%
Student3 1 A 1 A 1 6 3 60%
我的问题是:
我只考虑日期为17日和21日的日期XYZ Schedule 01
,我不想在报告中显示,并相应地计算百分比,我该如何实现?任何帮助都可能非常有用。
答案 0 :(得分:0)
取出几行代码。你应该拿出的第一行是
<TH>percentage(%)</TH>
您要删除的下两行是
$percent = number_format( $percent_cal * 100, 2 ) . '%';
echo '<td>'.$percent.'</td>';//Percentage