簡體   English   中英

使用PHP從MySQL數據庫中獲取數據

[英]Fetching data from MySQL Database using PHP

我有3張桌子,分別是:
1)出勤
2)注冊
3)時間表

1.出席
sl_no是注冊sl_no外鍵引用, AttID是主鍵

在此處輸入圖片說明

2.注冊
sl_no是主鍵

在此處輸入圖片說明

3.時間表
id是主鍵

在此處輸入圖片說明

我要對照schedule tableregistration table查詢數據庫,以獲取時間表的開始日期,結束日期和學生詳細信息where university is same以下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%

我的問題是:
我只希望在剩余的2天17日,19日和21 XYZ Schedule 01參加計划XYZ Schedule 01 ,我不希望在報告中顯示該日期,並據此計算百分比,我該如何實現? 任何幫助都可能會令人討厭。

取出幾行代碼。 您應該取出的第一行是

<TH>percentage(%)</TH>

您要刪除的下兩行是

$percent = number_format( $percent_cal * 100, 2 ) . '%'; 
echo '<td>'.$percent.'</td>';//Percentage

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM