Jump to content

Olumide

Members
  • Posts

    126
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Olumide

  1. I am a novice and working on a result project project for elementary school. There should a position such as 1st, 2nd, 3rd,... till the last person in the class with the lowest mark. I could not use the php ordinal suffix to this. I need your help to help me rectify this issue below and attached is the picture of the current output but instead of the only numbers, I something like the red painted numbers. $semester = $_GET['semester'] ?? ''; $class = $_GET['class'] ?? ''; $midend = $_GET['midend'] ?? 'M'; $res = $pdo->prepare("SELECT sessionid FROM semester WHERE id = ? "); $res->execute([$semester]); $session = $res->fetchColumn(); switch ($midend) { case 'M': $res = $pdo->prepare("SELECT subjectname , stname , score , @seq := IF(subjectname = @prevs, @seq+1, 1) as seq , @rank := IF(score = @prev, @rank, @seq) as rank , @prev := score as prev , @prevs := subjectname as prevs FROM ( SELECT cl.classname , sb.subjectname , concat(st.firstname, ' ', st.lastname) as stname , round( sum( case exam when 'Exam' then score/70*100 else score*10 end ) / COUNT(distinct exam) ) as score FROM student_class stc JOIN student st ON stc.studentid = st.id JOIN class cl ON stc.classid = cl.id JOIN level l ON cl.levelid = l.id JOIN course c ON l.id = c.levelid JOIN subject sb ON c.subjectid = sb.id JOIN result r ON r.courseid = c.id AND r.studentclassid = stc.id WHERE stc.semesterid = ? AND exam = 'CA1' AND cl.id = ? GROUP BY c.id, sb.id, st.id ORDER BY subjectname, score DESC LIMIT 9223372036854775807 -- MariaDB bug workaround ) ordered JOIN (SELECT @prevs:='', @prev:=0, @seq:=0, @rank:=0) init "); $res->execute([ $semester, $class ]); $chkm = 'checked'; $chke = $chky = ''; break; case 'E': $res = $pdo->prepare("SELECT subjectname , stname , score , @seq := IF(subjectname = @prevs, @seq+1, 1) as seq , @rank := IF(score = @prev, @rank, @seq) as rank , @prev := score as prev , @prevs := subjectname as prevs FROM ( SELECT sb.subjectname , concat(st.firstname, ' ', st.lastname) as stname , round( sum( score )) as score FROM student_class stc JOIN student st ON stc.studentid = st.id JOIN class cl ON stc.classid = cl.id JOIN level l ON cl.levelid = l.id JOIN course c ON l.id = c.levelid JOIN subject sb ON c.subjectid = sb.id JOIN result r ON r.courseid = c.id AND r.studentclassid = stc.id WHERE stc.semesterid = ? AND cl.id = ? GROUP BY c.id, sb.id, st.id ORDER BY subjectname, score DESC LIMIT 9223372036854775807 -- MariaDB bug workaround ) ordered JOIN (SELECT @prevs:='', @prev:=0, @seq:=0, @rank:=0) init "); $res->execute([ $semester, $class ]); $chke = 'checked'; $chkm = $chky = ''; break; default: $res = $pdo->prepare("SELECT subjectname , stname , score , @seq := IF(subjectname = @prevs, @seq+1, 1) as seq , @rank := IF(score = @prev, @rank, @seq) as rank , @prev := score as prev , @prevs := subjectname as prevs FROM ( SELECT sb.subjectname , concat(st.firstname, ' ', st.lastname) as stname , round( sum( score )/count(distinct sm.id)) as score FROM student_class stc JOIN student st ON stc.studentid = st.id JOIN class cl ON stc.classid = cl.id JOIN level l ON cl.levelid = l.id JOIN course c ON l.id = c.levelid JOIN subject sb ON c.subjectid = sb.id JOIN result r ON r.courseid = c.id AND r.studentclassid = stc.id JOIN semester sm ON stc.semesterid = sm.id JOIN session sn ON sm.sessionid = sn.id WHERE sm.sessionid = ? AND cl.id = ? GROUP BY cl.id, sb.id, st.id ORDER BY subjectname, score DESC LIMIT 9223372036854775807 -- MariaDB bug workaround ) ordered JOIN (SELECT @prevs:='', @prev:=0, @seq:=0, @rank:=0) init ORDER BY subjectname, score DESC "); $res->execute([ $session, $class ]); $chky = 'checked'; $chkm = $chke = ''; break; } function getOrdinalSuffix($score) { $score = abs($score) % 100; $lastChar = substr($score, -1, 1); switch ($lastChar) { case '1' : return ($score == '11') ? 'th' : 'st'; case '2' : return ($score == '12') ? 'th' : 'nd'; case '3' : return ($score == '13') ? 'th' : 'rd'; } return 'th'; } $list = ''; for ($score = 1; $score < 150; $score++) { $list .= "$score" . getOrdinalSuffix($score) . "\n"; } ///print "$list"; $data = []; foreach ($res as $r) { if (!isset($data[$r['subjectname']])) { $data[$r['subjectname']]['students'] = []; } $data[$r['subjectname']]['students'][] = [ 'name' => $r['stname'], 'score' => $r['score'], 'rank' => $r['rank'] ]; } function clsOpts($db, $current='') { $opts = "<option value=''>- select class -</option>\n"; $res = $db->query("SELECT id , classname FROM class ORDER BY substring(classname, 6, 2)+0 "); foreach ($res as $r) { $sel = $r['id'] == $current ? 'selected' : ''; $opts .= "<option $sel value='{$r['id']}'>{$r['classname']}</option>\n"; } return $opts; } function nameBar($name, $val) { $wid = 400; $ht = 32; $bar = "<svg width='90%' viewBox='0 0 $wid $ht'>\n <defs> <linearGradient id='pchi' x1='0' y1='0' x2='0' y2='1'> <stop offset='0%' stop-color='#54BC54'/> <stop offset='10%' stop-color='#54BC54'/> <stop offset='15%' stop-color='#eee'/> <stop offset='20%' stop-color='#54BC54'/> <stop offset='100%' stop-color='#0B7604'/> </lineargradient> <linearGradient id='pclo' x1='0' y1='0' x2='0' y2='1'> <stop offset='0%' stop-color='#E02222'/> <stop offset='10%' stop-color='#E02222'/> <stop offset='15%' stop-color='#eee'/> <stop offset='20%' stop-color='#E02222'/> <stop offset='100%' stop-color='#A91723'/> </lineargradient> <linearGradient id='pcmid' x1='0' y1='0' x2='0' y2='1'> <stop offset='0%' stop-color='#F2D335'/> <stop offset='10%' stop-color='#F2D335'/> <stop offset='15%' stop-color='#eee'/> <stop offset='20%' stop-color='#F2D335'/> <stop offset='100%' stop-color='#EC9807'/> </lineargradient> <style type='text/css'> rect { opacity: 0.2; } </style> </defs> "; $max = 100; $pix = $wid/$max; if ($val > $max) $val = $max; // percentage labels // for ($p=25; $p<=75; $p+=25) { // $ty=8; // $tx = $p * $pix; // $bar .= "<path d='M $tx $ty l 0 4' stroke='#AAA' /> // <text x='$tx' y='$ty' class='pcent' >{$p}%</text>\n"; // } // draw bar $w = $val * $pix; $h = $ht-12; // if ($val >= 80) $barfill = 'url(#pchi)'; // elseif ($val >= 50) $barfill = 'url(#pcmid)'; // else $barfill = 'url(#pclo)'; $barfill = 'url(#pchi)'; // $bar .= "<rect x='0' y='12' width='$wid' height='$h' stroke='#444' fill='#DDD' />\n"; $bar .= "<rect x='0' y='12' width='$w' height='$h' fill='$barfill' />\n"; $ty = $ht-4; $bar .= "<text x='4' y='$ty' fill='#000'>$name</text>\n"; $bar .= "</svg>\n"; return $bar; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Student Top Results</title> <link rel="stylesheet" href="assets/css/w3.css"> <!--<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> --> <script src="assets/js/jquery.js"></script> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready(function() { }) </script> <style type='text/css'> table { width: 94%; margin: 0 auto; } </style> </head> <body> <header class='w3-container w3-padding w3-margin'> <h1><img src='logo1.png' height='65' alt='logo'>Student Top Results</h1> </header> <div class='w3-bar w3-light-gray'> <form id='form1'> <label class='w3-bar-item' for='search'>Class </label> <select class='w3-input w3-bar-item w3-border ' name='class' id='class' > <?= clsOpts($pdo, $class) ?> </select> <label class='w3-bar-item' for='search'>Term </label> <select class='w3-input w3-bar-item w3-border ' name='semester' id='semester' > <?= semesterOptions($pdo, 0, $semester) ?> </select> <span class='w3-bar-item'> &emsp;<input type='radio' name='midend' value = 'M' <?=$chkm?>> Mid-term &emsp;<input type='radio' name='midend' value = 'E' <?=$chke?>> End-term &emsp;<input type='radio' name='midend' value = 'Y' <?=$chky?>> End-year </span> &emsp;<button class='w3-button w3-bar-item w3-blue-gray w3-margin-left'>Show lists</button> </form> </div> <div class='w3-container w3-margin-top'> <?php if ($data) { echo "<div class='w3-row'>"; foreach ($data as $subname => $subdata) { $studs = array_pad($subdata['students'], 3, ['name'=>'&nbsp;', 'score'=>'&nbsp;']); echo "<div class='w3-col w3-card s12 m4 w3-margin-top'> <div class='w3-panel w3-margin w3-padding w3-large w3-center w3-blue-gray'>$subname</div> <table>"; // for ($i=0; $i<3; $i++) { // $stud = $studs[$i]; // echo " // <tr><td><i class='fa fa-trophy' style='color: {$awards[$i]};'></i>&ensp; // {$stud['name']}</td> // <td>{$stud['score']}</td> // </tr> // "; // } foreach ($subdata['students'] as $k => $stud) { if (isset($awards[$stud['rank']])) { $trophy = "<i class='fa fa-trophy' style='color: {$awards[$stud['rank']]};'></i>"; } else $trophy = '&emsp;'; echo " <tr> <td>{$stud['rank']}</td> <td>$trophy&ensp; " . nameBar($stud['name'], $stud['score']) . "</td><td>{$stud['score']}</td> </tr>\n "; } echo "</table>\n</div>"; } } ?>
  2. if ($clid <= 0) { $res = $pdo->prepare("SELECT classid FROM student_class WHERE semesterid = ? AND studentid = ? "); $res->execute( [ $semester, $student ]); $clid = $res->fetchColumn(); } ################################################################################ # Get scores and put in array with required output structure # ################################################################################ $studentname = ''; $studentlevel = ''; $studentsession = ''; $studentsemester = ''; $studentterm = ''; $passport = ''; $level = '4'; $pupil_count = 0; $grand_total = 0; $subject_count = 0; $res = $pdo->prepare("SELECT st.id as stid , concat_ws(' ', st.lastname, st.firstname, st.othername) as stname , st.image , cl.classname , sc.classid , l.id as level , c.subjectid , s.subjectname , sn.sessionname , score*10 as ca FROM result r JOIN ( student_class sc JOIN class cl ON sc.classid = cl.id JOIN level l ON cl.levelid = l.id JOIN course c ON c.levelid = l.id JOIN student st ON sc.studentid = st.id JOIN semester sm ON sc.semesterid = sm.id JOIN session sn ON sm.sessionid = sn.id JOIN subject s ON c.subjectid = s.id ) ON r.studentclassid = sc.id AND exam = 'CA1' and r.courseid = c.id WHERE sn.id = ? AND studentid = ? AND sm.semestername+0 = ? ORDER BY c.levelid, sc.id, c.subjectid, sc.semesterid, exam "); $res->execute( [ $session, $student, $termno ] ); $data = []; $subject_count = 0; // get data common to all rows from first row $r = $res->fetch(); if ($r) { $studentname = $r['stname']; $studentlevel = $r['classname']; $studentsession = $r['sessionname']; $studentterm = "- Term $termno"; $level = $r['level']; $passport = "images/" . $r['image']; // then process the rest of the row data in the first and remaining rows do { if (!isset($data[ $r['subjectid'] ])) { $data[ $r['subjectid'] ] = [ 'name' => $r['subjectname'], #'exams' => ['CA1'=>'', 'CA2'=>''], #'ca' => [ 1=>0, 0, 0 ], 'ca' => 0, 'last' => 0, 'avg' => 0, 'terms' => 0 ]; } $data[ $r['subjectid'] ]['ca'] = $r['ca']; $subject_count += ($r['ca'] > 0); } while ($r = $res->fetch()); // $subject_count = count($data); // if ($subject_count == 0) $subject_count = 1; ################################################################################ # get prev terms' totals ################################################################################ $res = $pdo->prepare("SELECT c.subjectid , round(sum(score) ) as lastterm , count(distinct sm.id) as terms FROM result r JOIN course c ON r.courseid = c.id JOIN student_class stc ON r.studentclassid = stc.id JOIN semester sm ON stc.semesterid = sm.id WHERE sm.sessionid = ? AND stc.studentid = ? AND sm.semestername+0 <= ? GROUP BY c.subjectid "); $t1 = $termno - 1; $res->execute([ $session, $student, $t1 ]); foreach ($res as $r) { if (isset($data[$r['subjectid']])) { $data[$r['subjectid']]['last'] = $r['lastterm']; $data[$r['subjectid']]['terms'] = $r['terms']; } } ################################################################################ # get the avg scores for the class # ################################################################################ $avgs = classAverageScores($pdo, $clid, $session, $termno); foreach ($avgs as $s => $av) { if (isset($data[$s])) $data[$s]['avg'] = $av; } ################################################################################ # Get pupil count # ################################################################################ $res = $pdo->prepare("SELECT COUNT(DISTINCT stc.studentid) AS pupils FROM student_class stc JOIN semester sm ON sm.id = stc.semesterid JOIN result r ON stc.id = r.studentclassid WHERE sm.id = ? AND stc.classid = ? "); $res->execute([ $semester, $clid ]); $pupil_count = $res->fetchColumn(); } else { // $studentname = ''; // $studentlevel = ''; // $studentsession = ''; // $studentsemester = ''; // $studentterm = ''; // $passport = ''; // $level = '4'; // $pupil_count = 0; // $grand_total = 0; // $subject_count = 1; // $clid = 0; } ################################################################################ # Loop through the data array to construct the output table rows # ################################################################################ $tdata = ''; $n = 1; $grand_total = 0; // $subject_count = count($data); // if ($subject_count==0) $subject_count = 1; foreach ($data as $subid => $subdata) { $tdata .= "<tr><td>$n</td> <td>{$subdata['name']}</td>"; $tdata .= "<td>{$subdata['ca']}</td>"; //$total = round(($subdata['last'] + $subdata['ca'])/($subdata['terms']+1)); $total = $subdata['ca']; $grand_total += $total; if ($total > 0) { list($grade, $comment) = getGradeComment($pdo, $total, $level); } else { $grade = '-'; $comment = '-'; } $clr = GRADE_COLOUR[$grade] ?? '#000'; $tdata .= "<td>$total</td><td>{$subdata['avg']}</td><td style='color:$clr; font-weight: 600;'>$grade</td><td>$comment</td></tr>\n"; ++$n; } ################################################################################ # Get list of gradings # ################################################################################ $grade_list = getGradeList($pdo, $level); ################################################################################ # Get end of term comments # ################################################################################ $comments = getEOTComments($pdo, $student, $semester); ?> Please, I am still learning, this was designed by a Boss and my Mentor, he was so good to me but something transpired that made him to forsake me and here am I now stalked. I was instructed to modify this to suit our school mid term report. We do generate Mid Term Report for our student, which is usually done using the CA1, but now we need to add CA2. Each CA have a maximum score entry in the database which is maximum of 10, but while outputting it, the score will be multiply by 5 and CA1 + CA2 will be the total because the total will decide the grades and the total highest mark is 100 also. I have tried series of methods to add CA2 from the SQL query but not working for me From the picture attached (res.png), CA1 and CA2 values are different, and the value show here is only for CA1 while it is not outputting values for CA2. Please help me on how to fix this.
  3. I have dropped all the tables and restructured with the appropriate data types as instructed. But am yet to re-query the database again.
  4. Okay sir, I will change the data type. But hope this will solve the problem sir?
  5. Okay sir, I will observe that when posting code next. The marks will stored in the database result -- Table structure for table `tblresult` -- CREATE TABLE `tblresult` ( `Id` int(10) NOT NULL, `matricNo` varchar(50) NOT NULL, `levelId` varchar(10) NOT NULL, `semesterId` varchar(10) NOT NULL, `sessionId` varchar(10) NOT NULL, `Subjects` varchar(250) NOT NULL, `courseCode` varchar(50) NOT NULL, `courseUnit` varchar(50) NOT NULL, `score` varchar(50) NOT NULL, `scoreGradePoint` varchar(50) NOT NULL, `scoreLetterGrade` varchar(10) NOT NULL, `totalScoreGradePoint` varchar(50) NOT NULL, `dateAdded` varchar(50) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `tblresult` -- INSERT INTO `tblresult` (`Id`, `matricNo`, `levelId`, `semesterId`, `sessionId`, `Subjects`, `courseCode`, `courseUnit`, `score`, `scoreGradePoint`, `scoreLetterGrade`, `totalScoreGradePoint`, `dateAdded`) VALUES (58, 'SGS129', '3', '1', '2', 'English Language', 'ENGA', '3', '5', '0', 'F', '0', '2022-08-21'), (57, 'SGS129', '3', '1', '2', 'Mathematics', 'MATA', '3', '55', '2.75', 'BC', '8.25', '2022-08-21'), (56, 'SGS129', '3', '1', '2', 'French', 'FRCA', '3', '5', '0', 'F', '0', '2022-08-21');
  6. My courses don't expire. It should be permanent. It only changes for class, i.e. the course for Year 10 is different from Year 7 courses
  7. Here is the real for Higher college which is name as studentlist.php This code work by displaying the list of students in a selected class and if I clicked on a student, it will take me to the registered course/subjects for that student so I can be able to enter scores for the students. But what am trying to do is that, let assume we have 10 teachers, and each teacher take different subjects, such teacher will only be able to enter his own subject score. That is why I was trying to output the subjects instead of the students name and from the subjects, If I click say English, it should list all the students taking English instead of listing all the subjects for a specific students. A teacher teaches a class which comprises of like ten or more students, such will have to enter the score for his subject like English for all the students eg Class Name: Year 11 Science [Subject: English] SN | Students Name | Score 1. | Johnson Rufus | 40 ----- the score will be computed by the teacher 2. | Olumide David | 30 ----- to be entered 3. | Kayode Jon | 40 ---- to be entered Something like above. But here is the code for the studentlist.php <?php include('../includes/dbconnection.php'); include('../includes/session.php'); error_reporting(0); ?> <!doctype html> <!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <?php include 'includes/title.php';?> <meta name="description" content="Ela Admin - HTML5 Admin Template"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="apple-touch-icon" href="https://i.imgur.com/QRAUqs9.png"> <link rel="shortcut icon" href="../assets/img/student-grade.png" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css"> <link rel="stylesheet" href="../assets/css/cs-skin-elastic.css"> <link rel="stylesheet" href="../assets/css/lib/datatable/dataTables.bootstrap.min.css"> <link rel="stylesheet" href="../assets/css/style2.css"> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'> <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> --> <script> function showValues(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; } }; xmlhttp.open("GET","ajaxCall2.php?fid="+str,true); xmlhttp.send(); } } </script> </head> <body> <!-- Left Panel --> <?php $page="result"; include 'includes/leftMenu.php';?> <!-- /#left-panel --> <!-- Left Panel --> <!-- Right Panel --> <div id="right-panel" class="right-panel"> <!-- Header--> <?php include 'includes/header.php';?> <!-- /header --> <!-- Header--> <div class="breadcrumbs"> <div class="breadcrumbs-inner"> <div class="row m-0"> <div class="col-sm-4"> <div class="page-header float-left"> <div class="page-title"> <h1>Dashboard</h1> </div> </div> </div> <div class="col-sm-8"> <div class="page-header float-right"> <div class="page-title"> <!-- Log on to codeastro.com for more projects! --> <ol class="breadcrumb text-right"> <li><a href="#">Dashboard</a></li> <li><a href="#">Compute Result</a></li> <li class="active">Compute Result</li> </ol> </div> </div> </div> </div> </div> </div> <div class="content"> <div class="animated fadeIn"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"> <!-- Log on to codeastro.com for more projects! --> <strong class="card-title"><h3 align="center">Select Student to Compute Result (GPA)</h3></strong> </div> <div class="card-body"> <!-- Credit Card --> <div id="pay-invoice"> <div class="card-body"> <div class="<?php echo $alertStyle;?>" role="alert"><?php echo $statusMsg;?></div> <form method="Post" action=""> <div class="row"> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Level</label> <?php $query=mysqli_query($con,"select * from tbllevel"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="levelId" class="custom-select form-control">'; echo'<option value="">--Select Level--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['levelName'].'</option>'; } echo '</select>'; } ?> </div> </div> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Session</label> <?php $query=mysqli_query($con,"select * from tblsession where isActive = 1"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="sessionId" class="custom-select form-control">'; echo'<option value="">--Select Session--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['sessionName'].'</option>'; } echo '</select>'; } ?> </div> </div> </div> <div class="row"> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Faculty</label> <?php $query=mysqli_query($con,"select * from tblfaculty ORDER BY facultyName ASC"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="facultyId" onchange="showValues(this.value)" class="custom-select form-control">'; echo'<option value="">--Select Faculty--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['facultyName'].'</option>'; } echo '</select>'; } ?> </div> </div> <div class="col-6"> <div class="form-group"> <?php echo"<div id='txtHint'></div>"; ?> </div> </div> </div> <div> <button type="submit" name="submit" class="btn btn-success">View Student</button> </div> </form> </div> </div> </div> </div> <!-- .card --> </div><!--/.col--> <br><br> <div class="col-md-12"> <div class="card"> <div class="card-header"> <strong class="card-title"><h3 align="center">All Student</h3></strong> </div> <div class="card-body"> <table id="bootstrap-data-table" class="table table-hover table-striped table-bordered"> <thead> <tr> <th>#</th> <th>FullName</th> <th>MatricNo</th> <th>Level</th> <th>Faculty</th> <th>Department</th> <th>Session</th> <th>Date Added</th> <th>First Semester</th> <th>Second Semester</th> </tr> </thead> <tbody> <?php if(isset($_POST['submit'])) { $levelId=$_POST['levelId']; $sessionId=$_POST['sessionId']; $departmentId=$_POST['departmentId']; $facultyId=$_POST['facultyId']; $ret=mysqli_query($con,"SELECT tblstudent.Id, tblstudent.firstName, tblstudent.lastName, tblstudent.otherName,tblstudent.matricNo, tblstudent.dateCreated, tbllevel.levelName,tblfaculty.facultyName,tbldepartment.departmentName,tblsession.sessionName, tblstudent.levelId,tblstudent.sessionId,tblstudent.facultyId,tblstudent.departmentId from tblstudent INNER JOIN tbllevel ON tbllevel.Id = tblstudent.levelId INNER JOIN tblsession ON tblsession.Id = tblstudent.sessionId INNER JOIN tblfaculty ON tblfaculty.Id = tblstudent.facultyId INNER JOIN tbldepartment ON tbldepartment.Id = tblstudent.departmentId where tblstudent.levelId ='$levelId' and tblstudent.sessionId ='$sessionId' and tblstudent.departmentId ='$departmentId' and tblstudent.facultyId ='$facultyId'"); $cnt=1; while ($row=mysqli_fetch_array($ret)) { ?> <tr> <td><?php echo $cnt;?></td> <td><?php echo $row['firstName'].' '.$row['lastName'].' '.$row['otherName'];?></td> <td><?php echo $row['matricNo'];?></td> <td><?php echo $row['levelName'];?></td> <td><?php echo $row['facultyName'];?></td> <td><?php echo $row['departmentName'];?></td> <td><?php echo $row['sessionName'];?></td> <td><?php echo $row['dateCreated'];?></td> <td><a href="courseList.php?semesterId=1&matricNo=<?php echo $row['matricNo'];?>&levelId=<?php echo $row['levelId'];?>&facultyId=<?php echo $row['facultyId'];?>&departmentId=<?php echo $row['departmentId'];?>&sessionId=<?php echo $row['sessionId'];?>" title="Edit Details"><i class="fa fa-eye fa-1x"></i> View Course</a></td> <td><a href="courseList.php?semesterId=2&matricNo=<?php echo $row['matricNo'];?>&levelId=<?php echo $row['levelId'];?>&facultyId=<?php echo $row['facultyId'];?>&departmentId=<?php echo $row['departmentId'];?>&sessionId=<?php echo $row['sessionId'];?>" title="Edit Details"><i class="fa fa-eye fa-1x"></i> View Course</a></td> </tr> <?php $cnt=$cnt+1; } }?> </tbody> </table> </div> </div> </div> <!-- end of datatable --> </div> </div><!-- .animated --> </div><!-- .content --> <div class="clearfix"></div> <?php include 'includes/footer.php';?> </div><!-- /#right-panel --> <!-- Right Panel --> <!-- Scripts --> <script src="https://cdn.jsdelivr.net/npm/jquery@2.2.4/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.4/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/jquery-match-height@0.7.2/dist/jquery.matchHeight.min.js"></script> <script src="../assets/js/main.js"></script> <script src="../assets/js/lib/data-table/datatables.min.js"></script> <script src="../assets/js/lib/data-table/dataTables.bootstrap.min.js"></script> <script src="../assets/js/lib/data-table/dataTables.buttons.min.js"></script> <script src="../assets/js/lib/data-table/buttons.bootstrap.min.js"></script> <script src="../assets/js/lib/data-table/jszip.min.js"></script> <script src="../assets/js/lib/data-table/vfs_fonts.js"></script> <script src="../assets/js/lib/data-table/buttons.html5.min.js"></script> <script src="../assets/js/lib/data-table/buttons.print.min.js"></script> <script src="../assets/js/lib/data-table/buttons.colVis.min.js"></script> <script src="../assets/js/init/datatables-init.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#bootstrap-data-table-export').DataTable(); } ); // Menu Trigger $('#menuToggle').on('click', function(event) { var windowWidth = $(window).width(); if (windowWidth<1010) { $('body').removeClass('open'); if (windowWidth<760){ $('#left-panel').slideToggle(); } else { $('#left-panel').toggleClass('open-menu'); } } else { $('body').toggleClass('open'); $('#left-panel').removeClass('open-menu'); } }); </script> </body> </html> And here is the code for the courselist.php where the teacher will be able to enter his or her score <?php include('../includes/dbconnection.php'); include('../includes/session.php'); include('../includes/functions.php'); if(isset($_GET['matricNo']) && isset($_GET['levelId']) && isset($_GET['departmentId']) && isset($_GET['facultyId']) && isset($_GET['sessionId']) && isset($_GET['semesterId'])){ $matricNo = $_GET['matricNo']; $levelId = $_GET['levelId']; $departmentId = $_GET['departmentId']; $facultyId = $_GET['facultyId']; $sessionId = $_GET['sessionId']; $semesterId = $_GET['semesterId']; $stdQuery=mysqli_query($con,"select * from tblstudent where matricNo = '$matricNo'"); $rowStd = mysqli_fetch_array($stdQuery); $semesterQuery=mysqli_query($con,"select * from tblsemester where Id = '$semesterId'"); $rowSemester = mysqli_fetch_array($semesterQuery); $sessionQuery=mysqli_query($con,"select * from tblsession where Id = '$sessionId'"); $rowSession = mysqli_fetch_array($sessionQuery); $levelQuery=mysqli_query($con,"select * from tbllevel where Id = '$levelId'"); $rowLevel = mysqli_fetch_array($levelQuery); } else{ echo "<script type = \"text/javascript\"> window.location = (\"studentList.php\"); </script>"; } //------------------------------------ COMPUTE RESULT ----------------------------------------------- if (isset($_POST['compute'])){ $score=$_POST['score']; $N = count($score); $Subjects = $_POST['Subjects']; $courseCode = $_POST['courseCode']; $courseUnit = $_POST['courseUnit']; $dateAdded = date("Y-m-d"); $letterGrade = ""; $gradePoint = ""; $scoreGradePoint = 0.00; $totalCourseUnit = 0; $totalScoreGradePoint = 0; $gpa = ""; for($i = 0; $i < $N; $i++) { $score[$i]; //each scores entered $Subjects[$i]; // each Subjects $courseCode[$i]; // each course codes $courseUnit[$i]; //each course units $letterGrade = getScoreLetterGrade($score[$i]); //get the score letter grade (AA, A, AB, B etc) for each courses $gradePoint = getScoreGradePoint($score[$i]); //get the score grade points (4.00, 3.75, 3.50 etc) for each courses $scoreGradePoint = $courseUnit[$i] * $gradePoint; //multiply each course unit with their grade point ( 3 * 4 = 12) //Checks if result has been computed (MatricNo, level, semester and session) $que=mysqli_query($con,"select * from tblfinalresult where matricNo ='$matricNo' and levelId = '$levelId' and semesterId = '$semesterId' and sessionId = '$sessionId'"); $ret=mysqli_fetch_array($que); if($ret == 0){ //if no record exists, insert a record $query=mysqli_query($con,"insert into tblresult(matricNo,levelId,semesterId,sessionId,Subjects,courseCode,courseUnit,score,scoreGradePoint,scoreLetterGrade,totalScoreGradePoint,dateAdded) value('$matricNo','$levelId','$semesterId','$sessionId','$Subjects[$i]','$courseCode[$i]','$courseUnit[$i]','$score[$i]','$gradePoint','$letterGrade','$scoreGradePoint','$dateAdded')"); if ($query) { $totalCourseUnit += $courseUnit[$i]; //adds up all the course units $totalScoreGradePoint += $scoreGradePoint; //adds up all the score grade points //computes the gpa by dividing the total course unit by the total score grade point $gpa = round(($totalScoreGradePoint / $totalCourseUnit), 2); $classOfDiploma = getClassOfDiploma($gpa); //gets the class of diploma (Distinction, Upper, Lower etc) } else { $alertStyle ="alert alert-danger"; $statusMsg="An error Occurred!"; } }//end of check //echo 'Score = '.$score[$i].' Letter Grade = '.$letterGrade.' Grade point = '.$gradePoint.' totalGradePoint = '.$scoreGradePoint.'<br>'; }//end of loop //Checks if result has been computed (MatricNo, level, semester and session) $que=mysqli_query($con,"select * from tblfinalresult where matricNo ='$matricNo' and levelId = '$levelId' and semesterId = '$semesterId' and sessionId = '$sessionId'"); $ret=mysqli_fetch_array($que); if($ret > 0){ $alertStyle ="alert alert-danger"; $statusMsg="The result has been computed for this student for this semester, level and session!"; } else{ $querys = mysqli_query($con,"insert into tblfinalresult(matricNo,levelId,semesterId,sessionId,totalCourseUnit,totalScoreGradePoint,gpa,classOfDiploma,dateAdded) value('$matricNo','$levelId','$semesterId','$sessionId','$totalCourseUnit','$totalScoreGradePoint','$gpa','$classOfDiploma','$dateAdded')"); if ($querys) { $alertStyle ="alert alert-success"; $statusMsg="Result Computed Successfully!"; } else { $alertStyle ="alert alert-danger"; $statusMsg="An error Occurred!"; } } }//end of POST ?> <!doctype html> <!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <?php include 'includes/title.php';?> <meta name="description" content="Ela Admin - HTML5 Admin Template"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="apple-touch-icon" href="https://i.imgur.com/QRAUqs9.png"> <link rel="shortcut icon" href="../assets/img/student-grade.png" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.0/normalize.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lykmapipo/themify-icons@0.1.2/css/themify-icons.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pixeden-stroke-7-icon@1.2.3/pe-icon-7-stroke/dist/pe-icon-7-stroke.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.2.0/css/flag-icon.min.css"> <link rel="stylesheet" href="../assets/css/cs-skin-elastic.css"> <link rel="stylesheet" href="../assets/css/lib/datatable/dataTables.bootstrap.min.css"> <link rel="stylesheet" href="../assets/css/style2.css"> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'> <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> --> <script> //Only allows Numbers function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; } //Check if the value entered is greater than 100 and not less than 0 function myFunction() { var x, text; // Get the value of the input field with id="numb" x = document.getElementById("score").value; // If x is Not a Number or less than one or greater than 10 if (isNaN(x) || x < 1 || x > 100) { // text = "Value cannot be greater than 100 or less than 0"; alert("Invalid"); } else{ text = ""; } document.getElementById("demo").innerHTML = text; } </script> </head> <body> <!-- Left Panel --> <?php include 'includes/leftMenu.php';?> <div id="right-panel" class="right-panel"> <!-- Header--> <?php include 'includes/header.php';?> <!-- Header--> <div class="content"> <div class="animated fadeIn"> <div class="row"> <div class="col-lg-12"> <div class="card"> </div> <!-- .card --> </div><!--/.col--> <div class="col-md-12"> <div class="card"> <div class="card-header"> <strong class="card-title"><h4 align="center">Compute <?php echo $rowStd['firstName'].' '.$rowStd['lastName']?>'s&nbsp;<?php echo $rowLevel['levelName'];?>&nbsp;[<?php echo $rowSemester['semesterName'];?>] - Semester Result</h></strong> </div> <form method="post"> <div class="card-body"> <p id="demo"></p> <div class="<?php if(isset($alertStyle)){echo $alertStyle;}?>" role="alert"><?php if(isset($statusMsg)){echo $statusMsg;}?></div> <table class="table table-hover table-striped table-bordered"> <thead> <tr> <th>#</th> <th>Course</th> <th>Code</th> <th>Unit</th> <th>Score</th> </tr> </thead> <tbody> <?php $ret=mysqli_query($con,"SELECT tblcourse.courseCode,tblcourse.courseTitle,tblcourse.dateAdded,tblcourse.Id, tblcourse.courseUnit,tbllevel.levelName,tblfaculty.facultyName,tbldepartment.departmentName,tblsemester.semesterName,tblsubject.Subjects from tblcourse INNER JOIN tbllevel ON tbllevel.Id = tblcourse.levelId INNER JOIN tblsubject ON tblsubject.id = tblcourse.courseTitle INNER JOIN tblsemester ON tblsemester.Id = tblcourse.semesterId INNER JOIN tblfaculty ON tblfaculty.Id = tblcourse.facultyId INNER JOIN tbldepartment ON tbldepartment.Id = tblcourse.departmentId where tblcourse.levelId ='$levelId' and tblcourse.semesterId ='$semesterId' and tblcourse.departmentId ='$departmentId' and tblcourse.facultyId ='$facultyId'"); $cnt=1; while ($row=mysqli_fetch_array($ret)) { ?> <tr> <td><?php echo $cnt;?></td> <td><?php echo $row['Subjects'];?></td> <td><?php echo $row['courseCode'];?></td> <td><?php echo $row['courseUnit'];?></td> <td><input name="score[]" id="score" type="text" class="form-control" maxlength="3" onkeypress="return isNumber(event)" ></td> <input id="" value="<?php echo $row['Subjects'];?>" name="Subjects[]" type="hidden" class="form-control" > <input id="" value="<?php echo $row['courseCode'];?>" name="courseCode[]" type="hidden" class="form-control" > <input id="" value="<?php echo $row['courseUnit'];?>" name="courseUnit[]" type="hidden" class="form-control" > <input id="" name="" value="<?php echo $row['Id'];?>" type="hidden" class="form-control" > </tr> <?php $cnt=$cnt+1; }?> </tbody> </table> <button type="submit" onclick="myFunction()" name="compute" class="btn btn-success">Compute Result</button> </form> </div> </div> </div> <!-- end of datatable --> </div> </div><!-- .animated --> </div><!-- .content --> <div class="clearfix"></div> <?php include 'includes/footer.php';?> </div><!-- /#right-panel --> <!-- Right Panel --> <!-- Scripts --> <script src="https://cdn.jsdelivr.net/npm/jquery@2.2.4/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.4/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/jquery-match-height@0.7.2/dist/jquery.matchHeight.min.js"></script> <script src="../assets/js/main.js"></script> <script src="../assets/js/lib/data-table/datatables.min.js"></script> <script src="../assets/js/lib/data-table/dataTables.bootstrap.min.js"></script> <script src="../assets/js/lib/data-table/dataTables.buttons.min.js"></script> <script src="../assets/js/lib/data-table/buttons.bootstrap.min.js"></script> <script src="../assets/js/lib/data-table/jszip.min.js"></script> <script src="../assets/js/lib/data-table/vfs_fonts.js"></script> <script src="../assets/js/lib/data-table/buttons.html5.min.js"></script> <script src="../assets/js/lib/data-table/buttons.print.min.js"></script> <script src="../assets/js/lib/data-table/buttons.colVis.min.js"></script> <script src="../assets/js/init/datatables-init.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#bootstrap-data-table-export').DataTable(); } ); // Menu Trigger $('#menuToggle').on('click', function(event) { var windowWidth = $(window).width(); if (windowWidth<1010) { $('body').removeClass('open'); if (windowWidth<760){ $('#left-panel').slideToggle(); } else { $('#left-panel').toggleClass('open-menu'); } } else { $('body').toggleClass('open'); $('#left-panel').removeClass('open-menu'); } }); </script> </body> </html>
  8. Thank you sir for the great analysis. As I have said earlier, a novice will always be a novice until I become sound like you. I planned to remove the course unit as it is not needed for my project cos this is just for an upper elementary which require no course unit nor even faculty or department. I want to display data for a specified class to list the registered subjects such that if I click on a subject say English, it will take me to another form where I will be able to enter scores for each students in that selected class for the allotted subject 'English'. Please I will post the initial code for the tertiary in which I was trying to worked to change to the upper elementary.
  9. Good morning sir, as it is early morning here according to our GMT +1, and I appreciate your effort in helping me to get my long time headache resolved. As I said yesterday, I don't know much as am still learning and am always eager to learn more cos I love programming and want to be a good programmer. I am pretty sure, I still have many errors in my code but at least if am able to get it solved one by one. Below is my code for the class list, such that if I select say Year 11 Science, and I click on view, it should output the list of subjects associated with only Year 11 Science. <form method="Post" action=""> <div class="row"> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Level</label> <?php $query=mysqli_query($con,"select * from tbllevel"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="levelId" class="custom-select form-control">'; echo'<option value="">--Select Level--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['levelName'].'</option>'; } echo '</select>'; } ?> </div> </div> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Semester</label> <?php $query=mysqli_query($con,"select * from tblsemester where isActive = 1"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="semesterId" class="custom-select form-control">'; echo'<option value="">--Select Semester--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['semesterName'].'</option>'; } echo '</select>'; } ?> </div> </div> </div> <div class="row"> <div class="col-6"> <div class="form-group"> <label for="x_card_code" class="control-label mb-1">Faculty</label> <?php $query=mysqli_query($con,"select * from tblfaculty ORDER BY facultyName ASC"); $count = mysqli_num_rows($query); if($count > 0){ echo ' <select required name="facultyId" onchange="showValues(this.value)" class="custom-select form-control">'; echo'<option value="">--Select Faculty--</option>'; while ($row = mysqli_fetch_array($query)) { echo'<option value="'.$row['Id'].'" >'.$row['facultyName'].'</option>'; } echo '</select>'; } ?> </div> </div> <div class="col-6"> <div class="form-group"> <?php echo"<div id='txtHint'></div>"; ?> </div> </div> </div> <div> <!-- Log on to codeastro.com for more projects! --> <button type="submit" name="submit" class="btn btn-success">View Subject</button> </div> </form> </div> </div> </div> </div> <!-- .card --> </div><!--/.col--> <br><br> <div class="col-md-12"> <div class="card"> <div class="card-header"> <strong class="card-title"><h3 align="center">All Subjects</h3></strong> </div> <div class="card-body"> <table id="bootstrap-data-table" class="table table-hover table-striped table-bordered"> <thead> <tr><!-- Log on to codeastro.com for more projects! --> <th>#</th> <th>Subject Name</th> <!-- <th>MatricNo</th>--> <th>Level</th> <th>Faculty</th> <th>Department</th> <th>Session</th> <!-- <th>Date Added</th>--> <th>First Semester</th> <th>Second Semester</th> </tr> </thead> <tbody> <?php if(isset($_POST['submit'])) { $levelId=$_POST['levelId']; $sessionId=$_POST['semesterId']; $departmentId=$_POST['departmentId']; $facultyId=$_POST['facultyId']; $ret=mysqli_query($con,"SELECT tblcourse.Id,tblcourse.courseTitle, tbllevel.levelName,tblfaculty.facultyName,tbldepartment.departmentName,tblsemester.semesterName, tblcourse.levelId,tblcourse.semesterId,tblcourse.facultyId,tblcourse.departmentId,tblsubject.Subjects from tblcourse INNER JOIN tbllevel ON tbllevel.Id = tblcourse.levelId INNER JOIN tblsubject ON tblsubject.id = tblcourse.courseTitle INNER JOIN tblsemester ON tblsemester.Id = tblcourse.semesterId INNER JOIN tblfaculty ON tblfaculty.Id = tblcourse.facultyId INNER JOIN tbldepartment ON tbldepartment.Id = tblcourse.departmentId where tblcourse.levelId ='$levelId' and tblcourse.semesterId ='$semesterId' and tblcourse.departmentId ='$departmentId' and tblcourse.facultyId ='$facultyId'"); $cnt=1; while ($row=mysqli_fetch_array($ret)) { ?> <tr> <td><?php echo $cnt;?></td> <!-- <td><?php echo $row['firstName'].' '.$row['lastName'].' '.$row['otherName'];?></td>--> <td><?php echo $row['Subjects'];?></td> <!-- <td><?php echo $row['matricNo'];?></td>--> <td><?php echo $row['levelName'];?></td> <td><?php echo $row['facultyName'];?></td> <td><?php echo $row['departmentName'];?></td> <td><?php echo $row['semesterName'];?></td> <!--<td><?php echo $row['dateCreated'];?></td>--> <td><a href="courseList.php?semesterId=1&levelName=<?php echo $row['levelName'];?>&levelId=<?php echo $row['levelId'];?>&facultyId=<?php echo $row['facultyId'];?>&departmentId=<?php echo $row['departmentId'];?>&semesterId=<?php echo $row['semesterId'];?>" title="Edit Details"><i class="fa fa-eye fa-1x"></i> View Course</a></td> <td><a href="courseList.php?semesterId=2&levelName=<?php echo $row['levelName'];?>&levelId=<?php echo $row['levelId'];?>&facultyId=<?php echo $row['facultyId'];?>&departmentId=<?php echo $row['departmentId'];?>&semesterId=<?php echo $row['semesterId'];?>" title="Edit Details"><i class="fa fa-eye fa-1x"></i> View Course</a></td> </tr> <?php $cnt=$cnt+1; } }?> </tbody> </table> </div> </div> </div> <!-- end of datatable -->
  10. Well sir, I have only added English and Mathematics for Year 11, under tblcourse. Though I have all the subjects in table tblsubjects, and what I planned to do is to add the subjects to each class/level as per their requirement and to know who takes which subject, from the form, I select level as Year 11, and I select faculty as science, I assumed I should fetch the list of sciences subjects registered under Year 11 Science. Am sorry sir, I can't post code cos am on phone as my computer has shutdown due to power failure. Am a Nigerian, so we don't have dependable light and a Computer science student trying to learn.
  11. Thanks sir for your effort and am sorry for the late reply, we don't have light here. Here is the table for students and all the students are taking Mathematics -- Table structure for table `tblstudent` -- CREATE TABLE `tblstudent` ( `Id` int(20) NOT NULL, `firstName` varchar(255) NOT NULL, `lastName` varchar(255) NOT NULL, `otherName` varchar(255) NOT NULL, `matricNo` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `levelId` int(10) NOT NULL, `DOB` varchar(100) CHARACTER SET latin1 NOT NULL, `Phone` varchar(100) CHARACTER SET latin1 NOT NULL, `Email` varchar(100) CHARACTER SET latin1 NOT NULL, `facultyId` int(10) NOT NULL, `departmentId` int(10) NOT NULL, `sessionId` int(10) NOT NULL, `image` varchar(255) CHARACTER SET latin1 DEFAULT NULL, `dateCreated` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `tblstudent` -- INSERT INTO `tblstudent` (`Id`, `firstName`, `lastName`, `otherName`, `matricNo`, `password`, `levelId`, `DOB`, `Phone`, `Email`, `facultyId`, `departmentId`, `sessionId`, `image`, `dateCreated`) VALUES (35, 'Ojo', 'SHEBA', 'John', 'MAB/2018/20057', '123456', 7, '2008-04-09', '081400009', 'ani@yahoo.com', 5, 23, 1, 'f3e9961302568e44ef60c009e852ec921661074548.jpg', '2022-08-21'), (36, 'Dada', 'Idowu', 'ELIAS', 'MAB/2018/14229', '123456', 7, '2008-09-12', '08034757757', '080@gmail.com', 5, 23, 1, '21f24bd277df7b56c438acd26664115e1661075094.jpg', '2022-08-21'), (37, 'Shade', 'Peter', 'OLUWAFEMI', 'MAB/2018/14299', '123456', 7, '2008-07-18', '0803444444', 'sample@yahoo.com', 5, 23, 1, 'f41ca8eb5f82744baf9212714bfbfba61661075244.jpg', '2022-08-21'), (38, 'Desola', 'Pelumi', '', 'MAB/2018/18984', '123456', 7, '2010-05-18', '08059430000', '080as0000@gmail.com', 5, 23, 1, '838792531cf234c19ffc81ed8b7f0e781661075367.jpg', '2022-08-21'), (39, 'Aina', 'ADESUYI', 'Sowu', 'MAB/2018/13878', 'codeastro', 7, '2007-10-30', '08065555550', 'emia@yahoo.com', 5, 23, 1, '3362a7e6c8d9118e4a38b6009b340dc21661075555.jpg', '2022-08-21'), (40, 'Baba', 'Eniola', 'MICHAEL', 'MAB/2018/99483', '123456', 7, '2008-12-01', '08155555559', 'example@gmail.com', 5, 23, 1, 'b939949d3f5afd782198760a9fd871791661075700.jpg', '2022-08-21'), (41, 'Iyami', 'Mama', 'EBRUPHIHO', 'MAB/2018/16916', '123456', 7, '2007-07-24', '0808888826', 'oy@yahoo.com', 5, 23, 1, '97c02bbe49220ae56f2eb75a5432a2ef1661075870.jpg', '2022-08-21'); -- -------------------------------------------------------- --
  12. Okay Sir. This is my problem Sir, what am trying to do is electronic result and I used a secondary school as a case study in my country here. I want to designed it in such a way that each teachers will able to login to computer results from any students taking that subject. Let assume, am teaching Mathematics for Class A, if I login, I will select class A, and it will show the list of subjects class A are offering, so from the view course, I can click the one that relate to my subject which is Mathematics, this will now open to generate the list of students in class A with a text box to enter scores for each students for the subject Mathematics. I am sorry for my poor English.
  13. I named my class as tbllevel. Am sorry for the confusion. I classified my class as level Sir.
  14. Am sorry sir for the omission, here is it: CREATE TABLE `tbllevel` ( `Id` int(20) NOT NULL, `levelName` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `tbllevel` -- INSERT INTO `tbllevel` (`Id`, `levelName`) VALUES (1, 'Level One'), (2, 'Level Two'), (3, 'Year 7'), (4, 'Year 8'), (5, 'Year 9'), (6, 'Year 10'), (7, 'Year 11'), (8, 'Year 12');
  15. Okay. Thank you, but can that be the issue? Please
  16. oh am sorry, here are my tables: CREATE TABLE `tblcourse` ( `Id` int(11) NOT NULL, `courseTitle` varchar(255) NOT NULL, `courseCode` varchar(255) NOT NULL, `courseUnit` int(10) NOT NULL, `facultyId` varchar(255) NOT NULL, `departmentId` varchar(255) NOT NULL, `levelId` varchar(10) NOT NULL, `semesterId` varchar(20) NOT NULL, `dateAdded` varchar(50) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `tblcourse` -- INSERT INTO `tblcourse` (`Id`, `courseTitle`, `courseCode`, `courseUnit`, `facultyId`, `departmentId`, `levelId`, `semesterId`, `dateAdded`) VALUES (34, '2', 'MAT', 3, '5', '23', '7', '1', '2022-08-22'), (33, '1', 'ENG', 3, '5', '23', '7', '1', '2022-08-22'), (32, '16', 'HISA', 3, '9', '7', '3', '1', '2022-08-20'), (31, '12', 'YORA', 3, '9', '7', '3', '1', '2022-08-20'), (30, '24', 'PREA', 3, '9', '7', '3', '1', '2022-08-20'), (29, '23', 'NVEA', 3, '9', '7', '3', '1', '2022-08-20'), (28, '22', 'CCAA', 3, '9', '7', '3', '1', '2022-08-20'), (27, '21', 'CRKA', 3, '9', '7', '3', '1', '2022-08-20'), (26, '20', 'CPSA', 3, '9', '7', '3', '1', '2022-08-20'), (25, '19', 'BUSA', 3, '9', '7', '3', '1', '2022-08-20'), (24, '15', 'BSTA', 3, '9', '7', '3', '1', '2022-08-20'), (23, '13', 'FRCA', 3, '9', '7', '3', '1', '2022-08-20'), (22, '2', 'MATA', 3, '9', '7', '3', '1', '2022-08-20'), (21, '1', 'ENGA', 3, '9', '7', '3', '1', '2022-08-20'); -- -------------------------------------------------------- -- -- Table structure for table `tbldepartment` -- CREATE TABLE `tbldepartment` ( `Id` int(20) NOT NULL, `departmentName` varchar(255) NOT NULL, `facultyId` int(20) NOT NULL, `dateCreated` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `tbldepartment` -- INSERT INTO `tbldepartment` (`Id`, `departmentName`, `facultyId`, `dateCreated`) VALUES (1, 'IT Dept', 1, '2022-06-13'), (2, 'Accounting', 2, '2022-06-15'), (3, 'Law Science', 3, '2022-06-15'), (4, 'Industrial Engineering', 4, '2022-06-15'), (5, 'Electrical Engineering', 4, '2022-06-15'), (6, 'Law Science', 2, '2022-08-20'), (7, 'Year 7', 9, '2022-08-20'), (8, 'Year 8', 9, '2022-08-20'), (9, 'Year 9', 9, '2022-08-20'), (10, 'Year 7', 10, '2022-08-20'), (11, 'Year 8', 10, '2022-08-20'), (12, 'Year 9', 10, '2022-08-20'), (13, 'Year 7', 8, '2022-08-20'), (14, 'Year 8', 8, '2022-08-20'), (15, 'Year 9', 8, '2022-08-20'), (16, 'Year 10', 7, '2022-08-20'), (17, 'Year 11', 7, '2022-08-20'), (18, 'Year 12', 7, '2022-08-20'), (19, 'Year 10', 6, '2022-08-20'), (20, 'Year 11', 6, '2022-08-20'), (21, 'Year 12', 6, '2022-08-20'), (22, 'Year 10', 5, '2022-08-20'), (23, 'Year 11', 5, '2022-08-20'), (24, 'Year 12', 5, '2022-08-20'); -- -------------------------------------------------------- -- -- Table structure for table `tblfaculty` -- CREATE TABLE `tblfaculty` ( `Id` int(20) NOT NULL, `facultyName` varchar(255) NOT NULL, `dateCreated` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `tblfaculty` -- INSERT INTO `tblfaculty` (`Id`, `facultyName`, `dateCreated`) VALUES (1, 'Faculty 1', '2022-06-13'), (2, 'Faculty 2', '2022-06-15'), (3, 'Faculty 3', '2022-06-15'), (4, 'Faculty 4', '2022-06-15'), (5, 'Science', '2022-08-20'), (6, 'Arts', '2022-08-20'), (7, 'Commercial', '2022-08-20'), (8, 'Magnificient', '2022-08-20'), (9, 'Adventurous', '2022-08-20'), (10, 'Blossom', '2022-08-20'); -- -------------------------------------------------------- CREATE TABLE `tblsemester` ( `Id` int(20) NOT NULL, `semesterName` varchar(100) NOT NULL, `isActive` int(5) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `tblsemester` -- INSERT INTO `tblsemester` (`Id`, `semesterName`, `isActive`) VALUES (1, 'First Term', 1), (2, 'Second Term', 0), (3, 'Third Term', 0); CREATE TABLE `tblsession` ( `Id` int(20) NOT NULL, `sessionName` varchar(30) NOT NULL, `isActive` int(5) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `tblsession` -- INSERT INTO `tblsession` (`Id`, `sessionName`, `isActive`) VALUES (1, '2022/2023', 1), (2, '2020/2021', 0); CREATE TABLE `tblsubject` ( `id` int(100) NOT NULL, `Subjects` varchar(150) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `tblsubject` -- INSERT INTO `tblsubject` (`id`, `Subjects`) VALUES (1, 'English Language'), (2, 'Mathematics'), (3, 'Biology'), (4, 'Physics'), (5, 'Chemistry'), (6, 'Geography'), (7, 'Further Mathematics'), (8, 'Agricultural Science'), (9, 'Economics'), (10, 'Home Economics'), (11, 'Technical Drawing'), (12, 'Yoruba'), (13, 'French'), (14, 'Christian Religious Studies'), (15, 'Basic Science and Technology'), (16, 'History'), (17, 'Government'), (18, 'Civic Education'), (19, 'Business Studies'),
  17. Thank you sir for your prompt response. But this is what am trying to do sir, I select a class, lets assume, CLASS A is selected, it will output all the subjects in class A in tabular form like the attached picture but this is not showing only the selected class but it showed all the classes in the database. If a class is selected, it will output the subjects in that selected class and I can click on say English or any subjects such that it will redirect me to another link to computer scores for the students in that selected class offering that subject.
  18. I am trying to compute results for students, and I want to select a class so that it will list all the subjects associated with that class from the database instead of listing all the subjects in all classes, it should only list the selected subjects associated with that class names. <tr><!-- below is the code! --> $levelId=$_POST['levelId']; $sessionId=$_POST['semesterId']; $departmentId=$_POST['departmentId']; $facultyId=$_POST['facultyId']; $ret=mysqli_query($con,"SELECT tblcourse.Id,tblcourse.courseTitle, tbllevel.levelName,tblfaculty.facultyName,tbldepartment.departmentName,tblsemester.semesterName, tblcourse.levelId,tblcourse.semesterId,tblcourse.facultyId,tblcourse.departmentId,tblsubject.Subjects from tblcourse INNER JOIN tbllevel ON tbllevel.Id = tblcourse.levelId INNER JOIN tblsubject ON tblsubject.id = tblcourse.courseTitle INNER JOIN tblsemester ON tblsemester.Id = tblcourse.semesterId INNER JOIN tblfaculty ON tblfaculty.Id = tblcourse.facultyId INNER JOIN tbldepartment ON tbldepartment.Id = tblcourse.departmentId <!-- This is where the problem is, if I should remove the below code for the weher functions, it will output what I need but won't show the exact class, it will only show all the classes registered in my database ---> where tblcourse.levelId ='$levelId' and tblcourse.semesterId ='$semesterId' and tblcourse.departmentId ='$departmentId' and tblcourse.facultyId ='$facultyId'"); $cnt=1; while ($row=mysqli_fetch_array($ret)) { ?> <tr> <td><?php echo $cnt;?></td> <!-- <td><?php echo $row['firstName'].' '.$row['lastName'].' '.$row['otherName'];?></td>--> <td><?php echo $row['Subjects'];?></td> <!-- <td><?php echo $row['matricNo'];?></td>--> <td><?php echo $row['levelName'];?></td> <td><?php echo $row['facultyName'];?></td> <td><?php echo $row['departmentName'];?></td> <td><?php echo $row['semesterName'];?></td> <!--<td><?php echo $row['dateCreated'];?></td>-->
  19. I have created a "grading table" that declared my low marks, high marks, grade and comment. I also have my result table with the following column label 'id','subjectid','studentid','grades', 'comments'; to store the input results. My problem now is to create the php code to store what ever score that is entered and compare it with the assigned grades in the database. Below is my code

       


     

    {
            
            $marks=array();
        $class=$_POST['class'];
        $studentid=$_POST['studentid']; 
        $mark=$_POST['marks'];
        $grades=$_POST['grades'];
        $comments=$_POST['comments'];
        //coding
        
        $sum=$mark*10; //total marks
            $avg=$sum;
            if($avg>=0&&$avg<=50)
                $grades="Fail";
            if($avg>50&&$avg<=70)
                $grades="C";
            if($avg>70&&$avg<=80)
                $grades="B";
            if($avg>80&&$avg<=90)
                $grades="A";
            if($avg>90)
                $grade="E";
        //end
        
        
        
         $stmt = $dbh->prepare("SELECT tblsubjects.SubjectName,tblsubjects.id FROM tblsubjectcombination join  tblsubjects on  tblsubjects.id=tblsubjectcombination.SubjectId WHERE tblsubjectcombination.ClassId=:cid order by tblsubjects.SubjectName");
         $stmt2=$dbh->prepare("SELECT id,StudentId,ClassId,SubjectId,marks,grades,comments from tblresult join grading on marks between lowmark and himark");
        
         $stmt->execute(array(':cid' => $class));
          $sid1=array();
         while($row=$stmt->fetch(PDO::FETCH_ASSOC))
         {
        
        array_push($sid1,$row['id']);
           } 
          
        for($i=0;$i<count($mark);$i++){
            $mar=$mark[$i];
          $sid=$sid1[$i];
          //my code 
        //$totalmarks=$marks*10;
        
        $sql="INSERT INTO  result(StudentId,ClassId,SubjectId,marks,grades,comments) VALUES(:studentid,:class,:sid,:marks,:grades,:comments)";
        $query = $dbh->prepare($sql);
        $query->bindParam(':studentid',$studentid,PDO::PARAM_STR);
        $query->bindParam(':class',$class,PDO::PARAM_STR);
        $query->bindParam(':sid',$sid,PDO::PARAM_STR);
        $query->bindParam(':marks',$mar,PDO::PARAM_STR);
        $query->bindParam(':grades',$grades,PDO::PARAM_STR);
        $query->bindParam(':comments',$comments,PDO::PARAM_STR);
        $query->execute();
        $lastInsertId = $dbh->lastInsertId();
        if($lastInsertId)
        {
        $msg="Result added successfully";
        }
        else 
        {
        $error="Please correct the error";
        }
        }
        }
        ?>
        
          <!-- My Grading starts from here -->
           
        <!-- grading stop here -->  
        
        
                <script>
        function getStudent(val) {
            $.ajax({
            type: "POST",
            url: "get_student.php",
            data:'classid='+val,
            success: function(data){
                $("#studentid").html(data);
                
            }
            });
        $.ajax({
                type: "POST",
                url: "get_student.php",
                data:'classid1='+val,
                success: function(data){
                    $("#subject").html(data);
                    
                }
                });
        }
            </script>
        <script>
        
        function getresult(val,clid) 
        {   
            
        var clid=$(".clid").val();
        var val=$(".stid").val();;
        var abh=clid+'$'+val;
        //alert(abh);
            $.ajax({
                type: "POST",
                url: "get_student.php",
                data:'studclass='+abh,
                success: function(data){
                    $("#reslt").html(data);
                    
                }
                });
        }
        </script>
        
        
            </head>
            <body class="top-navbar-fixed">
                <div class="main-wrapper">
        
                    <!-- ========== NAVBAR ========== -->
          <?php include('includes/topbar.php');?> 
                    <!-- ========== SIDEBARS & MAIN CONTENT ========== -->
                    <div class="content-wrapper">
                        <div class="content-container">
        
                            <!-- ========== LEFT SIDEBAR ========== -->
                           <?php include('includes/leftbar.php');?>  
                            <!-- /.left-sidebar -->
        
                            <div class="main-page">
        
                             <div class="container-fluid">
                                    <div class="row page-title-div">
                                        <div class="col-md-6">
                                            <h2 class="title">Result Page</h2>
                                        
                                        </div>
                                        
                                                                   </div>
                                    <!-- /.row -->
                                    <div class="row breadcrumb-div">
                                        <div class="col-md-6">
                                            <ul class="breadcrumb">
                                                <li><a href="dashboard.php"><i class="fa fa-home"></i> Home</a></li>
                                        
                                                <li class="active">Student Result</li>
                                            </ul>
                                        </div>
                                     
                                    </div>
                                    <!-- /.row -->
                                </div>
                                <div class="container-fluid">
                                   
                                <div class="row">
                                            <div class="col-md-12">
                                                <div class="panel">
                                                   
                                                    <div class="panel-body">
        <?php if($msg){?>
        <div class="alert alert-success left-icon-alert" role="alert">
         <strong>Good job!</strong><?php echo htmlentities($msg); ?>
         </div><?php } 
        else if($error){?>
            <div class="alert alert-danger left-icon-alert" role="alert">
                                                    <strong>Try again!</strong> <?php echo htmlentities($error); ?>
                                                </div>
                                                <?php } ?>
                                                        <form class="form-horizontal" method="post">
        
         <div class="form-group">
        <label for="default" class="col-sm-2 control-label">Class</label>
         <div class="col-sm-10">
         <select name="class" class="form-control clid" id="classid" onChange="getStudent(this.value);" required="required">
        <option value="">Select Class</option>
        <?php $sql = "SELECT * from classes";
        $query = $dbh->prepare($sql);
        $query->execute();
        $results=$query->fetchAll(PDO::FETCH_OBJ);
        if($query->rowCount() > 0)
        {
        foreach($results as $result)
        {   ?>
        <option value="<?php echo htmlentities($result->id); ?>"><?php echo htmlentities($result->ClassName); ?></option>
        <?php }} ?>
         </select>
                                                                </div>
                                                            </div>
        <div class="form-group">
                                                                <label for="date" class="col-sm-2 control-label ">Student Name</label>
                                                                <div class="col-sm-10">
                                                            <select name="studentid" class="form-control stid" id="studentid" required="required" onChange="getresult(this.value);">
                                                            </select>
                                                                </div>
                                                            </div>
        
                                                            <div class="form-group">
                                                              
                                                                <div class="col-sm-10">
                                                            <div  id="reslt">
                                                            </div>
                                                                </div>
                                                            </div>
                                                            
        <div class="form-group">
                                                                <label for="date" class="col-sm-2 control-label">Subjects</label>
                                                                <div class="col-sm-10">
                                                            <div  id="subject">
                                                            </div>
                                                                </div>
                                                            </div>
        
        
                                                            
                                                            <div class="form-group">
                                                                <div class="col-sm-offset-2 col-sm-10">
                                                                    <button type="submit" name="submit" id="submit" class="btn btn-primary">SUBMIT</button>
                                                                </div>
                                                            </div>
                                                        </form>

  20. Thanks Boss, I have created the grading table as requested. But please what is now the php code to select the grades to assign to any score entered and post it to the result table. You have shown me the sql codes, but the php to perform the main task sir.
  21. Thanks Boss, I have created the grading table as requested. But please what is now the php code to select the grades to assign to any score entered and post it to the result table. You have shown me the sql codes, but the php to perform the main task sir.
  22. Thanks Boss, I have created the grading table as requested. But please what is now the php code to select the grades to assign to any score entered and post it to the result table. You have shown me the sql codes, but the php to perform the main task sir.
  23. Thanks for your response, but is there a way I can do it without having my low, high marks already in the database but have it in my code?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.