This tutorial covers the code of the calculator in PHP.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
<?php $sgpa=0; if(!empty($_POST["save"])) { $total_subjects = count($_POST["subject_name"]); $counter=0; $total_cr=$_POST['total_cr']; $sub_cr=$_POST["sub_cr"]; for($i=0;$i<$total_subjects;$i++) { $counter++; $sub_gpa=($_POST["subject_gpa"][$i]*$sub_cr[$i])/$total_cr; $sgpa+=$sub_gpa; } } ?> <!DOCTYPE html> <html> <head> <title>gpa</title> </head> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="http://code.jquery.com/jquery-2.1.1.js"></script> <script> function addMore() { $("<div>").load("getdata.php", function() { $("#subjects").append($(this).html()); }); } function deleteRow() { $('div.grab_values').each(function(index, item){ jQuery(':checkbox', this).each(function () { if ($(this).is(':checked')) { $(item).remove(); } }); }); } </script> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="index.php">GPA CALCULATOR</a> </div> <ul class="nav navbar-nav"> <li class="active"><a href="index.php"><span class="glyphicon glyphicon-home"></span>Calculate SGPA</a></li> <li><a href="cgpa.php"><span class="glyphicon glyphicon-flag"></span>Calculate CGPA</a></li> </ul> </div> </nav> <div class="container"> <div class="row"> <div class="col-lg-7 col-lg-offset-2"> <form method="post"> <b>Your SGPA : </b> <input type="text" class="form-control" placeholder="Your SGPA is" value="<?php print round($sgpa, 2) ;?>" readonly></input><br> <input type="text" name="total_cr" class="form-control" placeholder="Total Credit Hours" required></input> <table class="table" > <th>     </th> <th>Subject Name</th> <th>Subject GPA</th> <th>Subject Credit Hour</th> </table> <div id="subjects"> <?php include("getdata.php") ?> </div> <div> <br><br> <input type="button" class="btn btn-success" name="add_item" value="Add More" onClick="addMore();" /> <input type="button" class="btn btn-danger" name="del_item" value="Delete" onClick="deleteRow();" /> <input type="submit" name="save" value="Calculate" class="btn btn-primary"/> <br><br> </div> <div> </div> </form> </div> </div> </div> </body> </html> |
getdata.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> </head> <body> <div class="grab_values form-group" style="clear:both;"> <div style="float: left;"> <input type="checkbox" name="item_index[]"/> </div> <div style="float: left;"> <input type="text" class="form-control" placeholder="Subject name" name="subject_name[]" required/> </div> <div style="float: left;"> <input type="text" class="form-control" placeholder="Subject gpa" name="subject_gpa[]" required/> </div> <div style="float: left;"> <input type="text" class="form-control" placeholder="Subject credit hour"name="sub_cr[]" required/> </div><br><br> </div> </body> </html> |
cgpa.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
<?php $answer=0; if (isset($_POST['submit'])) { $current_gpa=$_POST['current_gpa']; $previous_semester=$_POST['previous_semester']; $expected=$_POST['expected']; $this_semester=$_POST['this_semester']; $sum=$current_gpa*$previous_semester; $sum1=$sum+$expected; $answer=$sum1/$this_semester; } ?> <!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="index.php">GPA CALCULATOR</a> </div> <ul class="nav navbar-nav"> <li><a href="index.php"><span class="glyphicon glyphicon-home"></span>Calculate SGPA</a></li> <li class="active"><a href="cgpa.php"><span class="glyphicon glyphicon-flag"></span>Calculate CGPA</a></li> </ul> </div> </nav> <div class="container"> <div class="row"> <div class="col-lg-5 col-lg-offset-3"> <form method="post" class="form-group"> <input type="text" name="current_gpa" placeholder="Current CGPA" class="form-control"></input><br><br> <input type="text" name="expected" placeholder="Expected CGPA" class="form-control"></input><br><br> <input type="text" name="previous_semester" placeholder="Your Previous Semester" class="form-control"></input><br><br> <input type="text" name="this_semester" placeholder="Your Current Semester" class="form-control"></input><br><br> <b>Your CGPA</b><br> <input type="text" class="form-control" placeholder="CGPA" value="<?php print round($answer, 2) ;?>" readonly></input><br><br> <input type="submit" name="submit" value="Calculate" class="btn btn-primary"></input><br><br> </form> </div> </div> </div> <center> <div class="alert alert-info"> <p>Your Previous Semester* (means the semester in which you appeared last time)</p> <p>Your current Semester* (means the semester in which you appeared recently)</p> </div> </center> </body> </html> |
Similarly, you can practice different examples of calculator in PHP.
Download Source Code of GPA calculator in PHP