Membuat Aplikasi Sederhana Grade Calculator Menggunakan PHP

Grade Calculator php

Kali ini kami akan share bagaimana membuat aplikasi sederhana Grade Calculator menggunakan PHP. Aplikasi seperti ini sangatbanyak digunakan pada system perguruan tinggi atau pada sekolah-sekolah.

Script pada aplikasi ini akan secara otomatis menghitung nilai siswa ketika pengguna memasukkan beberapa nilai. Script itu sendiri menggunakan rumus penjumlahan untuk menghitung nilai setiap siswa. 

Langsung saja mari kita masuk kedalama pembahasan inti.

1. Buat database dengan nama db_grade kemudian masukkan struktur database dibawah ini.

-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Mar 22, 2019 at 03:39 PM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `db_grade`
--

-- --------------------------------------------------------

--
-- Table structure for table `student`
--

CREATE TABLE `student` (
  `stud_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `prelim` int(10) NOT NULL,
  `midterm` int(10) NOT NULL,
  `endterm` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `student`
--

INSERT INTO `student` (`stud_id`, `name`, `prelim`, `midterm`, `endterm`) VALUES
(1, 'Arman Basir', 74, 74, 74);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `student`
--
ALTER TABLE `student`
  ADD PRIMARY KEY (`stud_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `student`
--
ALTER TABLE `student`
  MODIFY `stud_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

2. Buat file dengan nama conn.php script pada file ini sebagai koneksi database.

<?php
	$conn = mysqli_connect("localhost", "root", "", "db_grade");
	
	if(!$conn){
		die("Error: Failed to connect to database!");
	}
?>

3. Buat file dengan nama index.php file ini sebagai form utama pada aplikasi sederhana ini.

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
	</head>
<body>
	<nav class="navbar navbar-default">
		<div class="container-fluid">
			<a class="navbar-brand" href="https://jasawebsite.ooo">Jasawebsite</a>
		</div>
	</nav>
	<div class="col-md-3"></div>
	<div class="col-md-6 well">
		<h3 class="text-primary">PHP - Simple Grade Calculator</h3>
		<hr style="border-top:1px dotted #ccc;"/>
		<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add student</button>
		<br /><br />
		<table class="table table-bordered">
			<thead class="alert-info">
				<tr>
					<th>Name</th>
					<th>Prelim</th>
					<th>Midterm</th>
					<th>Endterm</th>
					<th>Final Grade</th>
					<th>Status</th>
				</tr>
			</thead>
			<tbody>
				<?php
					require 'conn.php';
					
					$query = mysqli_query($conn, "SELECT * FROM `student`") or die(mysqli_error());
					while($fetch = mysqli_fetch_array($query)){
					
					$final = ($fetch['prelim'] + $fetch['midterm'] + $fetch['endterm']) / 3;
				?>
				<tr>
					<td><?php echo $fetch['name']?></td>
					<td><?php echo $fetch['prelim']?></td>
					<td><?php echo $fetch['midterm']?></td>
					<td><?php echo $fetch['endterm']?></td>
					<td><?php echo $final?></td>
					<?php
						if($final >=75){
							echo "<td style='background-color:green; color:#fff;'>Pass</td>";
						}else if($final < 75){
							echo "<td style='background-color:red; color:#fff;'>Fail</td>";
						}
					?>
				</tr>
				<?php
					}
				?>
			</tbody>
		</table>
	</div>
<div class="modal fade" id="form_modal" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<form method="POST" action="save_student.php">
				<div class="modal-header">
					<h3 class="modal-title">Add Student</h3>
				</div>
				<div class="modal-body">
					<div class="col-md-2"></div>
					<div class="col-md-8">
						<div class="form-group">
							<label>Name</label>
							<input type="text" class="form-control" name="name" required="required"/>
						</div>
						<div class="form-group">
							<label>Prelim</label>
							<input type="number" min="0" max="100" class="form-control" name="prelim" required="required"/>
						</div>
						<div class="form-group">
							<label>Midterm</label>
							<input type="number" min="0" max="100" class="form-control" name="midterm" required="required"/>
						</div>
						<div class="form-group">
							<label>Endterm</label>
							<input type="number" min="0" max="100" class="form-control" name="endterm" required="required"/>
						</div>
					</div>
				</div>
				<br style="clear:both;"/>
				<div class="modal-footer">
					<button type="button" data-dismiss="modal" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Close</button>
					<button class="btn btn-primary" name="save"><span class="glyphicon glyphicon-save"></span> save</button>
				</div>
			</form>
		</div>
	</div>
</div>	
<script src="js/jquery-3.2.1.min.js"></script>	
<script src="js/bootstrap.js"></script>	
</body>	
</html>

4. Buat file dengan nama save_student.php file ini befungsi menyimpan file yang di input ketika anda menekan button save.

<?php
	require_once 'conn.php';
	
	if(ISSET($_POST['save'])){
		$name = $_POST['name'];
		$prelim = $_POST['prelim'];
		$midterm = $_POST['midterm'];
		$endterm = $_POST['endterm'];
		
		mysqli_query($conn, "INSERT INTO `student` VALUES('', '$name', '$prelim', '$midterm', '$endterm')") or die(mysqli_error());
		header("location: index.php");
	}
?>

Kalian bisa mendownload langsung filenya pada link button dibawah ini.

Sekian share kali ini semoga apa yang kami share bermanfaat bagi anda, jika kalian masih bingun silahkan tinggalkan komentar dan mulai berdiskusi dengan kami.

Leave a Reply

Your email address will not be published. Required fields are marked *