<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Compare Registration vs Result Score</title>
</head>
<body>
    <table border="1">
        
        <tr>
            <td>S/N</td>
            <td>Index Number</td>
            <td>Registred Courses</td>
            <td>Result Courses</td>
            <td>Status</td>
        </tr>
        <?php
                require_once('config.php');
                require_once('students.php');
            
                // Create an instance of the student class
                $studentObj = new Student($conn);
                $row = $studentObj->compareRegExam();
                $sn=0;
                
            while($fetch = mysqli_fetch_assoc($row)){
                $sn++;
                
            
        ?>
        <tr>
            <td><?php echo $sn; ?></td>
            <td>
                <?php 
                    $indexNumber = $fetch['reg_number']; 
                    echo $indexNumber; 
                ?>
            </td>
            
            <td>
                <?php 
            $studentRegisteredCourses = $studentObj->getStudentRegisteredCourses();
            if(isset($studentRegisteredCourses[$indexNumber])){//Check if Array Key of Examination number (Index Number) Exist
               
                $registeredCourses = ["registered_courses"=> $studentRegisteredCourses[$indexNumber]]; //Get Student Registered Course

            }else{//Else assign Empty Array

                $registeredCourses = [];

            }
                
               $registeredCousesQuery = $registeredCourses['registered_courses'];
               $registeredCousesArray = [];
               foreach($registeredCousesQuery as $courseCode){
                   $registeredCousesArray[] = $courseCode['course_code'];
               }
               $registeredCousesString = implode(", ", $registeredCousesArray);
                   echo ($registeredCousesString);
                ?>
            </td>
            <td>Result Courses</td>
            <td>Status</td>
        </tr>
        <?php
            }
        ?>
        
        
    </table>
</body>
</html>
