function courseset($student_id, $database)
{
    $dbc = dbconnect('local');
    $stu_completed = completedcourses($student_id);
    $set = array();
    $counter = 0;
    $loop = sizeof($stu_completed);
    $flag = 0;
    //	echo "$loop";
    for ($i = 0; $i < $loop; $i++) {
        //echo "$i";
        $rows = array();
        $coursecode = $stu_completed[$i]['course_code'];
        $query = " SELECT `course_set` FROM `{$database}` WHERE `course_code` = '{$coursecode}';";
        $result = $dbc->query($query) or die('.Error querying database. courseset');
        while ($row = $result->fetch_assoc()) {
            $rows[] = $row;
        }
        //echo $stu_completed[$i]['course_type'];
        if ($stu_completed[$i]['course_type'] == "ELECTIVE" || $stu_completed[$i]['course_type'] == "elective" || strcasecmp($stu_completed[$i]['course_type'], "elective") == 0) {
            //	echo "iambatman";
            if ($flag == 0) {
                $coursecode = "GCIS ELE";
                $flag = 2;
            } else {
                $coursecode = "GCIS ELE" . $flag;
                $flag++;
            }
            //	echo $coursecode;
            $query = " SELECT `course_set` FROM `{$database}` WHERE `course_code` = '{$coursecode}';";
            $result = $dbc->query($query) or die('.Error querying database. courseset');
            while ($row = $result->fetch_assoc()) {
                $rows[] = $row;
            }
            // print_r($rows);
        }
        if (!empty($rows)) {
            $set[$counter] = $rows[0]['course_set'];
            $counter++;
        }
    }
    /*echo "<pre>";
    	print_r($set);*/
    return $set;
}
<?php

include 'includes/session_define.php';
include 'includes/queries.php';
include 'includes/function.php';
include 'includes/header.php';
include 'includes/menu.php';
//echo "<pre>";print_r($_SESSION);
if (empty($_SESSION['student']) || !isset($_SESSION['student'])) {
    redirect_to("student_id_report.php");
}
$student_details = $_SESSION['student'];
//echo "reprot".$student_details['student_id'];
//sprint_r($_SESSION['student']);
$completed = completedcourses($student_details['student_id']);
$completed_loop = sizeof($completed);
$required = requiredcourses($student_details);
//echo "<pre>";
//print_r($required);
if (!empty($required['required'])) {
    $req_loop = sizeof($required['required']);
} else {
    $req_loop = 0;
}
if (!empty($required['foundation'])) {
    $foundation_loop = sizeof($required['foundation']);
} else {
    $foundation_loop = 0;
}
?>
    ?>
            <tr>
              <td><label for="studentid"><?php 
    echo $values[$i]['student_id'];
    ?>
</label></td>
              <td><label for="fname"><?php 
    echo $values[$i]['first_name'];
    ?>
</label></td>
              <td><label for="lname"><?php 
    echo $values[$i]['last_name'];
    ?>
</label></td>
              <?php 
    $stu_completed = completedcourses($values[$i]['student_id']);
    $stu_completed_list = array_column($stu_completed, 'course_code');
    $foundation_set = courseset($values[$i]['student_id'], $foundation_database);
    $stu_foundation_req = select_foundation($values[$i]['student_id']);
    $stu_foundation_req_course = array_column($stu_foundation_req, 'course_code');
    $stu_foundation_waived = select_waived_foundation($values[$i]['student_id']);
    $stu_foundation_waived_course = array_column($stu_foundation_waived, 'course_code');
    //echo"<pre>";print_r($stu_foundation_req_course);
    //echo"<pre>";print_r($foundation_set);
    //echo"<pre>";print_r($stu_foundation_waived_course);
    //echo"<pre>";print_r($foundation_set);
    ?>
              <?php 
    for ($c = 0; $c < sizeof($all_foundation); $c++) {
        ?>
              		<?php