Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // +----------------------------------------------------------------------+
- // | PHP version 5 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) Oyesanmi Oyedotun |
- // +----------------------------------------------------------------------+
- // | This source file is subject to version 2.0 of the PHP license, |
- // | that is bundled with this package in the file LICENSE, and is |
- // | available through the world-wide-web at |
- // | http://www.php.net/license/2_02.txt. |
- // | If you did not receive a copy of the PHP license and are unable to |
- // | obtain it through the world-wide-web, please send a note to |
- // | license@php.net so we can mail you a copy immediately. |
- // +----------------------------------------------------------------------+
- // | Authors: Oyesanmi Oyedotun <email dotunoyesanmi@gmail.com > |
- // +----------------------------------------------------------------------+
- ?>
- <?php session_start();
- if(!$_SESSION['logged_username']) {
- header('Location: http://127.0.0.1:8080/result/index.php');} ?>
- <?php require('includes/dbconnect.php'); ?>
- <?php require 'includes/header.inc.php'; ?>
- <?php
- if (isset($_POST['submit'])) {
- //variable input sanitization
- $matric_no = mysql_real_escape_string($_POST['matric_no']) ;
- $session = mysql_real_escape_string($_POST['session']) ;
- $semester_name = mysql_real_escape_string($_POST['semester_name']) ;
- $level = mysql_real_escape_string($_POST['level']) ;
- if (($_POST['matric_no'] == "") || ( $_POST['session'] == "") ||
- ($_POST['semester_name'] == "" ) || ($_POST['level'] == "" )) {
- echo "<div id=\"contentRight\">";
- echo"<id id=\"msg\">" ;
- echo "One of the form entry is empty.";
- echo"</div>" ;
- }
- else
- {
- //query to find if a combination of the user inputs are already in tthe database
- $query1 = "SELECT maintable.matric_no, maintable.session, maintable.semester_name, maintable.level
- FROM maintable
- WHERE maintable.matric_no = '$matric_no'
- AND maintable.session = '$session'
- AND maintable.semester_name = '$semester_name'
- AND maintable.level = '$level'";
- $result1 = mysql_query($query1) ;
- $duplicates1 = mysql_num_rows($result1);
- if ($duplicates1 < 1)
- {
- echo"<div id=\"contentRight\">";
- echo"<div id=\"msg\">" ;
- echo "You dont have a record for <span style=\"color:red\">$matric_no</span>" ;
- echo"</div>" ;
- echo"</div>" ;
- }
- //a seperate query from the main query to obtain name of the student
- //since it was iterating with the same information, from the query below.
- $query2 = mysql_query("SELECT first_name, last_name
- FROM students
- WHERE matric_no = '".$matric_no."' ");
- ($row2 = mysql_fetch_array($query2));
- //This query is used to obtain the Total Number of Course_units taken
- //in a semester
- $query3 = mysql_query("SELECT SUM(c.course_unit) AS 'TOTAL'
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'
- AND m.level = '".$level."'") or die (mysql_error());
- //this query is used to obtain columns to calculate the cgpa
- $query4 = mysql_query("SELECT c.course_unit, m.score
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'
- AND m.level = '".$level."'") or die (mysql_error());
- //this query is used to obtain columns to calculate the cgpa
- $query5 = mysql_query("SELECT c.course_unit, m.score
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'") or die (mysql_error());
- //This query is used to obtain the Cummulative Number of Coures_units
- //ever taken by the student
- $query6 = mysql_query("SELECT SUM(c.course_unit) AS 'TOTAL'
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'") or die (mysql_error());
- //This query takes columns from 3 tables, and the column c.course_unit, takes values from
- //the courses table
- $query7 = mysql_query("SELECT m.course_code AS 'Course Code', c.course_title AS 'Course Title', c.course_unit AS 'Unit', m.score AS 'Score', m.grade AS 'Grade'
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'
- AND m.level = '".$level."'") or die (mysql_error());
- $number_cols = mysql_num_fields($query7);
- //Query8 is used to determine the coureses that have a grade of "F".
- //It SELECT score and course_code values from the database for the required course taken by the student, in th
- $query8 = mysql_query("SELECT m.score, m.course_code
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'
- AND m.score >= 0 AND m.score < 40 ") or die (mysql_error());
- //Query9 is used to determine the coureses that have a grade of "AR".
- //It SELECT score and course_code values from the database for the required course taken by the student, in th
- $query9 = mysql_query("SELECT m.grade, m.course_code
- FROM maintable AS m
- INNER JOIN students AS s ON
- m.matric_no = s.matric_no
- INNER JOIN courses AS c ON
- m.course_code = c.course_code
- WHERE m.matric_no = '".$matric_no."'
- AND m.grade = 'AR'") or die (mysql_error());
- echo "<div id=\"contentRight\">" ;
- echo "<span class=\"header\">";
- echo "<p><b>Matric Number: $matric_no"." -- ". " ";
- echo "<b>First Name: ".$row2['first_name'].""." -- ". " ";
- echo "<b>Last Name: ".$row2['last_name']."</p>";
- echo "<p><b>Session: $session"." -- ". " ";
- echo "<b>Semester: $semester_name"." -- ". " ";
- echo "<b>Level: $level</b></p>";
- echo "<table border = \"1\" cellspacing = \"1\" cellpadding = \"4\" bgcolor = red >\n";
- echo "<tr align= \"center\">\n";
- $carry_over = array();
- $score_count = mysql_numrows($query8);echo "<th>"."Failed Courses";
- if($score_count !== 0){
- while ($row8 = mysql_fetch_assoc ($query8)) {
- echo"<td>". $row8['course_code']."</td>\n";
- }
- }
- echo "</tr>\n";
- echo "</table>";
- echo "<table border = \"1\" cellspacing = \"1\" cellpadding = \"1\" bgcolor = red >\n";
- echo "<tr align= \"center\">\n";
- $awaiting_result = array();
- $awaiting_result = mysql_numrows($query9);echo "<th>"."Awaiting Results";
- if($awaiting_result !== 0){
- while ($row9 = mysql_fetch_assoc ($query9)) {
- echo"<td>". $row9['course_code']."</td>\n";
- }
- }
- echo "</tr>\n";
- echo "</table>";
- //This displays the rows from the query into an html table.
- echo "<table border = \"1\" cellspacing = \"1\" cellpadding = \"1\" bgcolor = lemonchiffon >\n";
- echo "<tr align= \"center\">\n";
- echo "<th>"; //this echo out
- echo"s/n"; //the serial number
- echo "</th>\n"; //heading for the table
- for ($i=0; $i<$number_cols; $i++) {
- echo "<th>" . mysql_field_name($query7, $i). "</th>\n";
- } $serial = 0;
- while ($row = mysql_fetch_row($query7)) {
- $serial++;
- echo "<tr align=center>\n";
- echo"<td>";
- echo $serial;
- echo"</td>\n";
- foreach ($row as $value)
- {
- echo "<td>$value</td>\n";
- }
- while ($row8 = mysql_fetch_assoc($query8)) {
- if ( $grade == 'AR' )
- {
- continue;
- }
- if ($row8['score'] >= 70) {
- $grade = 'A';
- }
- elseif ( $row8['score'] >= 60 AND $row8['score'] < 70 ) {
- $grade = 'B';
- }elseif ($row8['score'] >= 50 AND $row8['score'] < 60) {
- $grade = 'C';
- }elseif ($row8['score'] >= 45 AND $row8['score'] < 50) {
- $grade = 'D';
- }elseif($row8['score'] >= 40 AND $row8['score'] < 45) {
- $grade = 'E';
- }elseif($row8['score'] >= 0 AND $row8['score'] < 40) {
- $grade = 'F';
- }else{
- $grade = 'AR';
- }
- }
- }
- $query11 = mysql_query("UPDATE maintable
- SET grade = CASE
- WHEN score >= 70 THEN 'A'
- WHEN score >= 60 AND score < 70 THEN 'B'
- WHEN score >= 50 AND score < 60 THEN 'C'
- WHEN score >= 45 AND score < 50 THEN 'D'
- WHEN score >= 40 AND score < 45 THEN 'E'
- WHEN score >= 0 AND score < 40 THEN 'F'
- ELSE 'AR'
- END;") or die(mysql_error());
- for ($i=0; $i<$number_cols; $i++) {
- echo "</tr>\n";
- echo "</table>";
- }
- while ($row3 = mysql_fetch_row($query3))
- {
- foreach ($row3 as $value3)
- {
- echo "<td>Present TNU: $value3</td>\n";
- }
- }
- while ($row6 = mysql_fetch_row($query6))
- {
- foreach ($row6 as $value6)
- {
- echo "<td>Cummulative TNU: $value6</td><br/>\n";
- }
- }
- $grade_point = 0;
- while ($row4 = mysql_fetch_assoc($query4)) {
- if ($row4['score'] >= 70) {
- $score = 5;
- }
- elseif ($row4['score'] >= 60) {
- $score = 4;
- }elseif ($row4['score'] >= 50) {
- $score = 3;
- }elseif ($row4['score'] >= 45) {
- $score = 2;
- }elseif($row4['score'] >= 40) {
- $score = 1;
- }else{
- $score = 0;
- }
- $grade_point += $score * $row4['course_unit'];
- }
- echo "Present TCP : $grade_point ";
- $grade_point1 = 0;
- while ($row5 = mysql_fetch_assoc($query5)) {
- if ($row5['score'] >= 70) {
- $score = 5;
- }
- elseif ($row5['score'] >= 60) {
- $score = 4;
- }elseif ($row5['score'] >= 50) {
- $score = 3;
- }elseif ($row5['score'] >= 45) {
- $score = 2;
- }elseif($row5['score'] >= 40) {
- $score = 1;
- }else{
- $score = 0;
- }
- $grade_point1 += $score * $row5['course_unit'];
- }
- echo "Cummulative TCP : $grade_point1 <br/>";
- $present_gpa = sprintf("%.2f", ( $grade_point / $value3)) ;
- $cummulative_gpa = sprintf("%.2f", ( $grade_point1 / $value6)) ;
- echo "Present GPA : $present_gpa ";
- echo "Cummulative GPA : $cummulative_gpa ";
- echo"</span>" ;
- echo"</div>";
- echo"</div>";
- require 'includes/footer.php';
- exit();
- }
- }
- ?>
- <div id="contentRight">
- <p>
- <span class="header">Update Student Bio Data</span>
- Enter the appropriate options below
- <form action="check_result.php" method="post">
- <ul>
- <li>Matric Number: <input type="text" name="matric_no"> </li><br />
- <li>Session: <select name="session">
- <option value =""> </option>
- <option value ="2011/2012">2011/2012</option>
- <option value ="2012/2013">2012/2013</option>
- <option value ="2013/2014">2013/2014</option>
- <option value ="2014/2015">2014/2015</option>
- <option value ="2015/2016">2015/2016</option>
- <option value ="2016/2017">2016/2017</option>
- <option value ="2017/2018">2017/2018</option>
- <option value ="2018/2019">2018/2019</option>
- <option value ="2019/2020">2019/2020</option>
- <option value ="2020/2021">2020/2021</option>
- <option value ="2021/2022">2014/2015</option>
- <option value ="2022/2023">2015/2016</option>
- <option value ="2023/2024">2016/2017</option>
- <option value ="2024/2025">2017/2018</option>
- <option value ="2025/2026">2018/2019</option>
- <option value ="2026/2027">2019/2020</option>
- <option value ="2027/2028">2020/2021</option>
- </select></li> <br />
- <li>Semester: <?php
- $result = mysql_query("SELECT *
- FROM semester") or die(mysql_error());
- echo'<select name = "semester_name">';
- echo'<option value =""> </option>';
- while($row = mysql_fetch_array($result)){
- echo '<option value="'.$row['semester_name'].'">'.$row['semester_name'].'</option>';}
- echo '</select>' ; ?></li><br />
- <li>Level:
-
-
-
- <?php
- $result1 = mysql_query("SELECT *
- FROM year") or die(mysql_error());
- echo'<select name = "level">';
- echo'<option value =""> </option>';
- while($row1 = mysql_fetch_array($result1)){
- echo '<option value="'.$row1['level'].'">'.$row1['level'].'</option>';}
- echo '</select>' ; ?> </li><br />
- <input type="submit" name="submit" value="Check Result" />
- <input type="hidden" name="submitted" value="TRUE" />
- <input name="Reset" type="reset" value="Reset" />
- </ul>
- </div>
- </div>
- </div>
- </form>
- <?php require 'includes/footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement