2014-12-09 136 views
-2

我需要從數據庫中檢索相關數據,並再次添加到考勤表中。這段代碼顯示了很多錯誤。實際上我不知道如何使用數組添加數據。誰能幫忙? thankssssssssssss。檢索並將數據添加到數據庫中

<?php 

    $sql = "select p_module_ID, student_ID, 
        p_attendance_Date, p_attendance_Time, 
        p_attendance_Status,p_attendance_reason 
        from attendance"; 

    $result = mysqli_query($con, $sql); 
    if(!$result) 
    { 
     echo mysqli_error($con); 
     exit(); 
    } 

    while($rows = mysqli_fetch_array($result)) 
    { 
     $attendance_list[] = array('p_module_ID' => $rows['p_module_ID'], 
           'student_ID' => $rows['student_ID'], 
           'p_attendance_Date' => $rows['p_attendance_Date'], 
           'p_attendance_Time' => $rows['p_attendance_Time'], 
           'p_attendance_Status' => $rows['p_attendance_Status'], 
           'p_attendance_reason' => $rows['p_attendance_reason']); 
    }   

    ?> 

    <html> 

    <body> 
    <form action="attendance.php" method="post" accept-charset='UTF-8'> 

    <table border="0" cellspacing="20" > 
    <tr> 
     <td> 
      <select name="p_module_ID"> 
       <?php 

       $sql = "SELECT p_module_ID FROM schedule"; 
       $result = $con->query($sql); 

        while($row = mysqli_fetch_assoc($result)) { 
         echo "<option>".$row['p_module_ID']."</option>"; 
        } 
       ?> 
      </select> 
     </td> 
    </tr> 


    <tr> 
     <td> 
      <select name="p_attendance_Date" > 
      <?php 

       $sql = "SELECT p_StartDate FROM schedule"; 
       $result = $con->query($sql); 

        while($row = mysqli_fetch_assoc($result)) { 
         echo "<option>".$row['p_StartDate']."</option>"; 
        } 
      ?> 
      </select> 
     </td> 
    </tr> 

    <tr> 
     <td> 
      <select name="p_attendance_Time"> 
      <?php 

       $sql = "SELECT p_Time FROM schedule"; 
       $result = $con->query($sql); 

        while($row = mysqli_fetch_assoc($result)) { 
         echo "<option>".$row['p_Time']."</option>"; 
        } 
       ?> 
      </select> 
     </td> 
    </tr> 

    <table id="t01"> 

     <tr> 
     <th> Student ID </th> 
     <th> Name </th> 
     <th> Attendance </th> 
     <th> Reason </th> 

     <?php foreach($attendance_list as $attend) : ?> 

      <tr> 
       <td> 
        <?php 
        $sql = "SELECT p.student_ID,CONCAT(s.student_fname, ' ', s.student_lname) AS fullname FROM Pals p JOIN student s ON p.student_ID = s.student_ID WHERE student_role = 'Student' GROUP BY student_ID"; 
        $result = $con->query($sql); 

        while($row = mysqli_fetch_assoc($result)) { 
        echo $attend[$row['student_id']]; 
        } 
        ?> 
       </td> 

       <td> 
        <?php 
        $sql = "SELECT p.student_ID,CONCAT(s.student_fname, ' ', s.student_lname) AS Fullname FROM Pals p JOIN student s ON p.student_ID = s.student_ID WHERE student_role = 'Student' GROUP BY student_ID"; 
        $result = $con->query($sql); 

        while($row = mysqli_fetch_assoc($result)) { 
        echo $attend['Fullname']; 
        } 
        ?> 
       </td> 

       <td> 
        <?php echo $attend["p_attendance_Status"]; ?> 
       </td> 

       <td> 
        <?php echo $attend["p_attendance_reason"]; ?> 
       </td> 

      </tr> 

     </tr> 

      <?php endforeach; ?> 

    </table> 


    </table> 
    </form> 
    </body> 
    </html> 
+0

請添加您的錯誤。 – Dinistro 2014-12-09 13:32:23

+0

注意:Undefined index:student_id in C:\ wamp \ www \ Mine \ attendance.php on line 138
注意:未定義的索引:全名在C:\ wamp \ www \ Mine \ attendance.php在149行@Dinistro – penguinnnnn 2014-12-09 13:33:35

+0

請將錯誤添加到您的問題中,並在代碼中標出引發錯誤的行。 – baao 2014-12-09 13:36:17

回答

0

使用$row['student_Id']而不是$row['student_id']。與Fullname相同。您選擇AS fullname而不是AS Fullname。傾聽大小寫敏感。

相關問題