query("SELECT * FROM user_account WHERE username = '$username'"); //First we need to get the user's own class_id and school_id if ($result->num_rows == 1) { //As each account has unique username and email //These information is required based on the accounType while ($row = $result->fetch_assoc()) { $user_school_id = $row['school_id']; $email = $row['email']; $accountType = $row['accountType']; //Now we fetch the class_id to fetch their class name from school_class //$user_class_id = $row['class_Id']; $user_id = $row['user_id']; } } //Next we need to load all school names $schoolResults = $conn->query("SELECT * FROM school"); if ($schoolResults->num_rows > 0) { while ($row = $schoolResults->fetch_assoc()) { $schoolNames[$row['school_id']] = $row['school_name']; } } //Than we need to load all the class names // $classResults = $conn->query("SELECT * FROM school_class"); // if ($classResults->num_rows > 0) { // while ($row = $classResults->fetch_assoc()) { // $classNames[$row['class_id']] = $row['class_name']; // } // } if($accountType == 2){ $classResults = $conn->query("SELECT * FROM school_class WHERE teacher_id = '$user_id'"); if($classResults->num_rows > 0){ while($row = $classResults->fetch_assoc()){ $classNames[$row['class_id']] = $row['class_name']; } } }else if($accountType == 3){ //before we fetch the class $classResults = $conn->query("SELECT * FROM school_class WHERE school_id = '$user_school_id'"); if($classResults->num_rows > 0){ while($row = $classResults->fetch_assoc()){ $classNames[$row['class_id']] = $row['class_name']; } } }else if($accountType > 3){ $classResults = $conn->query("SELECT * FROM school_class"); if($classResults->num_rows > 0){ while($row = $classResults->fetch_assoc()){ $classNames[$row['class_id']] = $row['class_name']; } } }else{ //this shouldn't be the case } //Upto this point we have got school and class names for all ?>

Greenscape Environmental Experience & Learning Survey Experiments

Manage Students

query("SELECT survey_id AS 'ID', survey_name AS 'Survey-Name', survey_url AS 'URL' FROM survey ORDER BY survey_id ASC"); if ($accountType == 2 || $accountType == '2') { //In this case we have account type of teacher //1. We need to get his/her class id\ //2. Since each teacher can have multiple classes so we store it in an array $userCreatedClass_Ids = array(); $teacherResult = $conn->query("SELECT * FROM school_class WHERE teacher_id = '$user_id'"); if ($teacherResult->num_rows) { //As each teacher can have only one class while ($row = $teacherResult->fetch_assoc()) { //this would be a list of id of user's class array_push($userCreatedClass_Ids, $row['class_id']); } } $allClassStudentsString = "SELECT user_id AS 'ID', username AS 'Username', email AS 'Email', password AS 'Password', school_id AS 'School-Name', class_id AS 'Class-Name', active AS 'Active' FROM user_account WHERE accountType = '1' AND school_id = '$user_school_id' AND ("; //that is user is a teacher but does not have a class if(count($userCreatedClass_Ids) == 0){ $allClassStudentsString .= " class_id = '0');"; }else{ for ($i = 0; $i < count($userCreatedClass_Ids); $i++) { //THis would mean the last class id of that user $classId = $userCreatedClass_Ids[$i]; if ($i == (count($userCreatedClass_Ids) - 1)) { $allClassStudentsString = $allClassStudentsString . " class_id = '$classId');"; } else { $allClassStudentsString = $allClassStudentsString . " class_id = '$classId' OR "; } } } $result = $conn->query($allClassStudentsString); } else if ($accountType == 3 || $accountType == '3') { $result = $conn->query("SELECT user_id AS 'ID', username AS 'Username', email AS 'Email', password AS 'Password', school_id AS 'School-Name', class_id AS 'Class-Name', active AS 'Active' FROM user_account WHERE accountType = '1' AND school_id = '$user_school_id'"); } else if ($accountType > 3) { //We fetch results for all students from all school and all classes $result = $conn->query("SELECT user_id AS 'ID', username AS 'Username', email AS 'Email', password AS 'Password', school_id AS 'School-Name', class_id AS 'Class-Name', active AS 'Active' FROM user_account WHERE accountType = '1'"); } else { //This shouldn't be the case as this page is only meant for role above 1 header('location:dashboard.php'); } $tablesAndTheirData = array(); array_push($tablesAndTheirData, array( 'fields' => $result->fetch_fields(), 'data' => $result )); foreach ($tablesAndTheirData as $table) { if ($table['data']->num_rows) { ?> fetch_assoc()) { $order_num++; ?> $value) { if ($key == 'ID') { $index = $value; } ?>
name; ?>
Add Student

New Student

Submit!