-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
ginerjm's Achievements
Single Status Update
-
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>