Jump to content

Olumide

Members
  • Posts

    132
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Olumide

  1. 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>-->
  2. 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>

  3. 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.
  4. 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.
  5. 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.
  6. 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?
  7. My question is: how can I do it such that after entering scores for each subject, the grades will be automatically calculated and post to the database.
  8. Am working on a project such that if I enter scores for each subjects, it will post to the database with the grades and comment. My form will only accept value for scores which will determine the grades for each subjects and hence post to the database. Like in Microsoft Excel whereby you have data (integers) and you instruct the excel (lets say you have your value in cell A1, and Cell A2 contains the formula: if(A1>=90,"A",if(A1>=80,"B","F")). I used switch case for the grade in my php code written below. { $marks=array(); $class=$_POST['class']; $studentid=$_POST['studentid']; $mark=$_POST['marks']; $grades=$_POST['grades']; $comments=$_POST['comments']; $stmt = $dbh->prepare("SELECT subjects.SubName,subjects.id FROM subjectlist join subjects on subjects.id=subjectlist.SubjectId WHERE subjectlist.ClassId=:cid order by subjects.SubName"); $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]; $totalmarks=$marks*10; $sql="INSERT INTO studresult(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(); $lastId = $dbh->lastId(); if($lastId) { $msg="Result successfully added"; } else { $error=" Please try again"; } } } ?> <!-- My Grading starts from here --> <?php switch(true) { case $totalmarks>=90 && $totalmarks<101: $grade = 'A*'; $comment='Congratulation!'; break; case $totalmarks>=85 && $totalmarks<90: $grade = 'A1'; $comment='Distinction'; break; case $totalmarks>=80 && $totalmarks<85: $grade = 'B2'; $comment='Very Good'; break; case $totalmarks>=75 && $totalmarks<80: $grade = 'B3'; $comment='Good'; break; case $totalmarks>=70 && $totalmarks<75: $grade = 'C4'; $comment='Credit'; break; case $totalmarks>=65 && $totalmarks<70: $grade = 'C5'; $comment='Credit'; break; case $totalmarks>=60 && $totalmarks<65: $grade = 'C6'; $comment='Credit'; break; case $totalmarks>=55 && $totalmarks<60: $grade = 'D7'; $comment='Pass'; break; case $totalmarks>=50 && $totalmarks<55: $grade = 'E8'; $comment='Pass'; break; case $totalmarks>=40 && $totalmarks<50: $grade = 'F9'; $comment='Fail'; break; default: $grade = 'F9'; $comment='Ungraded'; break; } ?> <!-- grading stop here -->
×
×
  • 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.