Skip to content

Instantly share code, notes, and snippets.

@ajdeguzman
Created October 2, 2014 14:39
Show Gist options
  • Save ajdeguzman/14eef33319140c92babe to your computer and use it in GitHub Desktop.
Save ajdeguzman/14eef33319140c92babe to your computer and use it in GitHub Desktop.
Calculate Grade
<?php
session_start();
include('conn.php');
if(isset($_GET['subj_id'])){$_SESSION['subj_id'] = $_GET['subj_id'];}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link type = "text/css" rel = "stylesheet" href="finalproj.css" />
<title>StudenTracker | Quiz</title>
<script type="text/javascript">
function calculatePassingScore() {
var quizItems = document.getElementById('quizItems').value;
var quizRate = document.getElementById('quizRate').value;
var quizPassing = document.getElementById('quizPassing');
quizPassing.value = (Number(quizItems) * Number(quizRate))/100 ;
}
function calculateGrade() {
var quizItems = document.getElementById('quizItems').value;
var quizScore = document.getElementsByClassName('quizScore');
var quizGrade = document.getElementsByClassName('quizGrade');
for(var i = 0; i < quizScore.length;i++){
quizGrade[i].value = (Number(quizScore[i].value) / Number(quizItems))*100;
if(quizGrade[i].value == quizPassing.value)
{
quizGrade[i].value = 3.0
}
if (quizGrade[i].value == Number (quizPassing) + 1)
{
quizGrade[i].value = 3.0
}
}
}
</script>
</head>
<body id ="pagewrap">
<br />
<div class="wrapper row1">
<div id="header" class="clear">
<div class="float_left">
<h1><a href="index.html"><image src = "logo.png" width="330" height="100"></a></h1>
</div>
<div id="topnav">
<ul>
</ul>
</div>
</div>
</div>
<br />
<div class="row">
<div class="col-md-8 col-md-offset-2 col-centered">
<form action="quiz.php" method="post">
<h4>Faculty ID:&nbsp;<span class = "label label-primary"><?php echo $_SESSION['faculty_id'] ?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="attendance.php">Attendance</a>&nbsp;&nbsp;| <a href="grade_options.php">Grades</a>&nbsp;&nbsp;</h4></form>
<!--<pre><?php //echo "Date: ". date("Y/m/d");?></pre>-->
<br />
<table class='table table-striped'>
<tr>
<td>No. of Items</td>
<td><input class = 'form-text-control' type = 'text' name='items_quiz' id='quizItems' onkeyup="calculatePassingScore();" /></td>
<td>Passing Rate</td>
<td><input class = 'form-text-control' type = 'text' name='rate_quiz' id='quizRate' onkeyup="calculatePassingScore();" /></td>
<td>Passing Score</td>
<td><input class = 'form-text-control' type = 'text' name='passing_quiz' id='quizPassing' onkeyup="calculatePassingScore();" /></td>
</tr>
<!--<tr>
<td>Score</td>
<td><input class = 'form-text-control' type = 'text' name='score_quiz' id='quizScore' onkeyup="calculateGrade();" /></td>
<td>Grade</td>
<td><input class = 'form-text-control' type = 'text' name='grade_quiz' id='quizGrade' onkeyup="calculateGrade();" /></td>
</tr>-->
<?php
include('conn.php');
$faculty_id = $_SESSION['faculty_id'];
echo "<tr>
<th>STUDENT ID</th>
<th>NAME</th>
<th>SCORE</th>
<th>GRADE</th>
</tr>";
$query = mysql_query("SELECT * FROM tblsubjects WHERE faculty_id = '". $faculty_id . "'");
if(mysql_num_rows($query) != 0){
while($row = mysql_fetch_array($query))
{
$subj_id = $row['subject_id'];
//echo "<td>".'Section: '.$row['stud_yrsec']."</td>";
$query2 = mysql_query("SELECT * FROM tblstudents WHERE faculty_id = '". $faculty_id . "' AND subject_id = '". $row['subject_id'] . "'");
//$subj_id = $row2['subject_id'];
//$yrsec = $row['stud_yrsec'];
while($row2 = mysql_fetch_array($query2)) {
$stud_id = $row2['student_id'];
$present_query = mysql_query("SELECT subject_id FROM tblquiz WHERE student_id = '". $stud_id . "'");
echo "<tr>";
echo "<td>".$stud_id."</td>";
echo "<td><a href = '#?stud_id=$stud_id'>".$row2['lname'].', '.$row2['fname'].' '.$row2['mname']."</a></td>";
echo "<td>".'<input class = "form-text-control quizScore" type = "text" name="score_quiz" onkeyup="calculateGrade()">'."</td>";
echo "<td>".'<input class = "form-text-control quizGrade" type = "text" name="grade_quiz" onkeyup="calculateGrade()">'."</td>";
while($row3 = mysql_fetch_array($present_query)) {
//echo "<td><input $checked class = 'isPresent' type='checkbox' name='sym_attend' value='".$row2['student_id']."' /></td>";
}
echo "</tr>";
}
}
}
?>
<tr>
<td><a href ="grade_options.php">Back</a></td>
<td><a href="quiz.php"><input type = "submit" name="button" value="Save"></td>
</tr>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment