Kali ini saya akan membuat contoh tentang input dan output database menggunakan php, syarat untuk bisa input dan output database tentu saja harus ada databasenya dulu, untuk membuatnya saya disini menggunkan phpmyadmin, ok langsung aja
pertama kita buka phpmyadmin nya kemudian klik new database, dan create database.
contoh saya membuat database baru yang diberi nama murid :
setelah database dibuat maka selanjutnya membuat table dn isi tributnya seperti gambar di bawah :
isi atributnya
Setelah Database dan tablenya berhasil dibuat, sekarang tinggal cara bagaimana untuk input data ke database menggunakan php, di sini saya menggunakan fungsi mysqli_connect, kodingannya seperti dibaha ini :
<?php
$db = mysqli_connect("localhost","root","","murid");
if(isset($_POST['simpan'])){
$namamurid = $_POST['nama'];
$nimmurid = $_POST['nim'];
$senjatamurid = $_POST['senjata'];
$sql = "INSERT INTO manusia (nama,nim,senjata) VALUES ('$namamurid','$nimmurid','$senjatamurid')";
$inputdata = mysqli_query($db,$sql);
if(!$inputdata){
die("gagal memasukan data" .mysqli_connect_error());
}else {
echo 'berhasil';
}
}
mysqli_close($db);
?>
<h2>ISI DATA</h2>
<pre>
<form method="post">
NAMA :<input type="text" name="nama"></input>
NIM :<input type="text" name="nim"></input>
SENJATA :<input type="text" name="senjata"></input>
<button type="submit" name="simpan">Simpan</button> <button type="submit">Reset</button>
</form>
</pre>
<a href="lihatdata.php">Lihat data</a>
dan tampilannya seperti gambar di bawah :
pada gambar di atas saya memasukan data nama nim dan senjata dan ketika di klik simpan data akan tersimpan di database, seperti pada gambar di bawah :
Dan cara untuk menampilkan /output database'a adalah dengan menuliskan koding di bawah :
<?php
$db = mysqli_connect("localhost","root","","murid");
?>
<h2>Tampil Database</h2>
<a href="isidata.php">isi database</a></br>
<?php
$sql = "SELECT * FROM manusia";
$tampil = mysqli_query($db, $sql);
while($data = mysqli_fetch_array($tampil)){
echo "Nama : $data[0]<br>";
echo "Nim : $data[1]<br>";
echo "Senjata : $data[2]<br><hr>";
}
?>
dan akan tampil seperti gambar ini :
Oke sekian Terimakasih
Wednesday, 13 April 2016
Wednesday, 6 April 2016
DAFTAR HARGA BBM(Bahan Bakar Minyak) MENGGUNAKAN PHP
Kali ini ane mau posting tentang tugas salah satu matakuliah, tugasnya itu disuruh bikin daftar hargga bbm, ok langsung saja untuk tampilan programnya:
Gambar diatas adalah tampilan programnya, dimana liter awal dimulai 1, dan liter akhirnya 10, data yang ditampilkan yaitu data Bensin, solar, dan minyak tanah, untuk source codenya diabawah:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TABEL HARGA BBM</title>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<div align="center"><br />
<h1>DAFTAR HARGA BBM</h1>
</div>
<br />
<form co id="bahan_bakar_minyak" name="bahan_bakar_minyak" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" />
<table border="1.7" align="center">
<tr>
<td bgcolor="#ff9999" align="center">Liter Awal</td>
<td bgcolor="#ff9999" align="center">Liter Akhir</td>
<td bgcolor="#ff9999" align="center">Bensin</td>
<td bgcolor="#ff9999" align="center">Solar</td>
<td bgcolor="#ff9999" align="center">Minyak Tanah</td>
</tr>
<tr>
<td align="center">
<select name="liter_awal" id="liter_awal">
<?php
for ($a=1;$a<=20;$a++){
echo "<option value='$a'"?>
<?php if ($_POST[liter_awal]=="$a") echo "selected"; ?>
<?php echo ">$a</option>";
}
?>
</select>
</td>
<td align="center">
<select name="liter_akhir" id="liter_akhir">
<?php
for ($a=1;$a<=20;$a++){
echo "<option value='$a'"?>
<?php if ($_POST[liter_akhir]=="$a") echo "selected"; ?>
<?php echo ">$a</option>";
}
?>
</select>
</td>
<td align="center">
<input type="checkbox" name="bensin" id="bensin" value="jenis" <?php if ($_POST[bensin]=="jenis") echo "checked"; ?>/>
</td>
<td align="center">
<input type="checkbox" name="solar" id="solar" value="jenis" <?php if ($_POST[solar]=="jenis") echo "checked"; ?> />
</td>
<td align="center">
<input type="checkbox" name="minyak_tanah" id="minyak_tanah" value="jenis" <?php if ($_POST[minyak_tanah]=="jenis") echo "checked"; ?> />
</td>
</tr>
<tr>
<td colspan="5" align="center">
<input type="submit" name="Tampilkan" id="Tampilkan" value="Tampilkan" />
</td>
</tr>
</table>
<hr color="pink" size="2" width="500" />
<?php
$liter_awal=0;
$liter_akhir=0;
$tampung=0;
$bensin="";
$solar="";
$minyak_tanah="";
$harga_bensin=8000;
$harga_solar=7000;
$harga_minyak_tanah=10000;
$liter_awal=$_POST[liter_awal];
$liter_akhir=$_POST[liter_akhir];
$bensin=$_POST[bensin];
$solar=$_POST[solar];
$minyak_tanah=$_POST[minyak_tanah];
?>
<?php
if($_POST[Tampilkan]=="Tampilkan"){ ?>
<?php
if ($liter_awal > $liter_akhir){
$tampung=$liter_awal;
$liter_awal=$liter_akhir;
$liter_akhir=$tampung;
}
if(($bensin=="jenis") && ($solar=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="350" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_solar2=$harga_solar*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($bensin=="jenis") && ($solar=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td bgcolor="#ff9999" width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_solar2=$harga_solar*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($bensin=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($solar=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_solar2=$harga_solar*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td>";?>
<?php echo "<td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($minyak_tanah=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($bensin=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($solar=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Solar</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_solar2=$harga_solar*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
{
?>
<table width="200" border="1" align="center">
<tr>
<td width="200" align="center">Maaf! Bahan Bakar Anda harus diisi</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
echo "<tr><td></td></tr>";}
}
}
else
{
?>
<table width="450" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=1;$a<=10;$a++){
$harga_bensin2+=$harga_bensin;
$harga_solar2+=$harga_solar;
$harga_minyak_tanah2+=$harga_minyak_tanah;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
?>
</table>
</body>
</html>
Sekian dan terimakasih.......
Gambar diatas adalah tampilan programnya, dimana liter awal dimulai 1, dan liter akhirnya 10, data yang ditampilkan yaitu data Bensin, solar, dan minyak tanah, untuk source codenya diabawah:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TABEL HARGA BBM</title>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<div align="center"><br />
<h1>DAFTAR HARGA BBM</h1>
</div>
<br />
<form co id="bahan_bakar_minyak" name="bahan_bakar_minyak" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" />
<table border="1.7" align="center">
<tr>
<td bgcolor="#ff9999" align="center">Liter Awal</td>
<td bgcolor="#ff9999" align="center">Liter Akhir</td>
<td bgcolor="#ff9999" align="center">Bensin</td>
<td bgcolor="#ff9999" align="center">Solar</td>
<td bgcolor="#ff9999" align="center">Minyak Tanah</td>
</tr>
<tr>
<td align="center">
<select name="liter_awal" id="liter_awal">
<?php
for ($a=1;$a<=20;$a++){
echo "<option value='$a'"?>
<?php if ($_POST[liter_awal]=="$a") echo "selected"; ?>
<?php echo ">$a</option>";
}
?>
</select>
</td>
<td align="center">
<select name="liter_akhir" id="liter_akhir">
<?php
for ($a=1;$a<=20;$a++){
echo "<option value='$a'"?>
<?php if ($_POST[liter_akhir]=="$a") echo "selected"; ?>
<?php echo ">$a</option>";
}
?>
</select>
</td>
<td align="center">
<input type="checkbox" name="bensin" id="bensin" value="jenis" <?php if ($_POST[bensin]=="jenis") echo "checked"; ?>/>
</td>
<td align="center">
<input type="checkbox" name="solar" id="solar" value="jenis" <?php if ($_POST[solar]=="jenis") echo "checked"; ?> />
</td>
<td align="center">
<input type="checkbox" name="minyak_tanah" id="minyak_tanah" value="jenis" <?php if ($_POST[minyak_tanah]=="jenis") echo "checked"; ?> />
</td>
</tr>
<tr>
<td colspan="5" align="center">
<input type="submit" name="Tampilkan" id="Tampilkan" value="Tampilkan" />
</td>
</tr>
</table>
<hr color="pink" size="2" width="500" />
<?php
$liter_awal=0;
$liter_akhir=0;
$tampung=0;
$bensin="";
$solar="";
$minyak_tanah="";
$harga_bensin=8000;
$harga_solar=7000;
$harga_minyak_tanah=10000;
$liter_awal=$_POST[liter_awal];
$liter_akhir=$_POST[liter_akhir];
$bensin=$_POST[bensin];
$solar=$_POST[solar];
$minyak_tanah=$_POST[minyak_tanah];
?>
<?php
if($_POST[Tampilkan]=="Tampilkan"){ ?>
<?php
if ($liter_awal > $liter_akhir){
$tampung=$liter_awal;
$liter_awal=$liter_akhir;
$liter_akhir=$tampung;
}
if(($bensin=="jenis") && ($solar=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="350" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_solar2=$harga_solar*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($bensin=="jenis") && ($solar=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td bgcolor="#ff9999" width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_solar2=$harga_solar*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($bensin=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if(($solar=="jenis") && ($minyak_tanah=="jenis"))
{ ?>
<table width="250" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_solar2=$harga_solar*$a;
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td>";?>
<?php echo "<td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($minyak_tanah=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_minyak_tanah2=$harga_minyak_tanah*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($bensin=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_bensin2=$harga_bensin*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
if($solar=="jenis")
{ ?>
<table width="150" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Solar</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
$harga_solar2=$harga_solar*$a;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td></tr>";}
}
else
{
?>
<table width="200" border="1" align="center">
<tr>
<td width="200" align="center">Maaf! Bahan Bakar Anda harus diisi</td>
</tr>
<?php for($a=$liter_awal;$a<=$liter_akhir;$a++){
echo "<tr><td></td></tr>";}
}
}
else
{
?>
<table width="450" border="1" align="center">
<tr>
<td width="50" align="center">Liter</td>
<td width="100" align="center">Bensin</td>
<td width="100" align="center">Solar</td>
<td width="100" align="center">Minyak Tanah</td>
</tr>
<?php for($a=1;$a<=10;$a++){
$harga_bensin2+=$harga_bensin;
$harga_solar2+=$harga_solar;
$harga_minyak_tanah2+=$harga_minyak_tanah;
echo "<tr><td align=right>$a</td><td align=right>";?>
<?php echo number_format($harga_bensin2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_solar2,0,",",".");?>
<?php echo "</td><td align=right>";?>
<?php echo number_format($harga_minyak_tanah2,0,",",".");?>
<?php echo "</td></tr>";}
}
?>
</table>
</body>
</html>
Sekian dan terimakasih.......
Monday, 4 April 2016
CONTOH SEDERHANA KALKULATOR OOP JAVA
Pertama buat class kalkulator yang isinya berupa method-method seperti untuk pembagian, perkalian dan sebagainya
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testingapp;
/**
*
* @author ikbal
*/
public class Kalkulator {
double operan1;
double operan2;
void isiOperan1(double x){
operan1 = x;
}
void isiOperan2(double y){
operan2 = y;
}
double tambah(){
return operan1+operan2;
}
double kurang(){
return operan1 - operan2;
}
double kali(){
return operan1*operan2;
}
double bagi(){
return operan1/operan2;
}
double pangkat(){
return Math.pow(operan1,operan2);
}
}
Dan untuk mengetest apakah jalan atau tidak kita buat klas lagi yaitu kalkulatortester langsung aja:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testingapp;
/**
*
* @author ikbal
*/
public class Kalkulatortester {
public static void main (String[] aghs ){
Kalkulator ikbal = new Kalkulator();
ikbal.isiOperan1(10);
ikbal.isiOperan2(3);
System.out.println("Tambah : "+ikbal.tambah());
System.out.println("Kurang : "+ikbal.kurang());
System.out.println("kali : "+ikbal.kali());
System.out.println("Bagi : "+ikbal.bagi());
System.out.println("Pangkat : "+ikbal.pangkat());
}
}
ok sekiatn dulu, jika ingin bertanya silahkan wasalah...
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testingapp;
/**
*
* @author ikbal
*/
public class Kalkulator {
double operan1;
double operan2;
void isiOperan1(double x){
operan1 = x;
}
void isiOperan2(double y){
operan2 = y;
}
double tambah(){
return operan1+operan2;
}
double kurang(){
return operan1 - operan2;
}
double kali(){
return operan1*operan2;
}
double bagi(){
return operan1/operan2;
}
double pangkat(){
return Math.pow(operan1,operan2);
}
}
Dan untuk mengetest apakah jalan atau tidak kita buat klas lagi yaitu kalkulatortester langsung aja:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testingapp;
/**
*
* @author ikbal
*/
public class Kalkulatortester {
public static void main (String[] aghs ){
Kalkulator ikbal = new Kalkulator();
ikbal.isiOperan1(10);
ikbal.isiOperan2(3);
System.out.println("Tambah : "+ikbal.tambah());
System.out.println("Kurang : "+ikbal.kurang());
System.out.println("kali : "+ikbal.kali());
System.out.println("Bagi : "+ikbal.bagi());
System.out.println("Pangkat : "+ikbal.pangkat());
}
}
ok sekiatn dulu, jika ingin bertanya silahkan wasalah...
Saturday, 2 April 2016
PROGRAM PECAHAN UANG MENGGUNAKAN PHP
Program Pemecahan Uang menggunakan PHP
By: Oky Saputra
Program pecahan uang ini berfungsi untuk menentukan berapakah saja jumlah yang diperlukan untuk nominal tertentu.
Misalkan pecahan uang 150rb diinputkan maka pecahan yang dibutuhkan adalah uang 100000 satu lembar dan 50 rb 1 lembar, ok untuk lebih jelasnya kita lihat gambar dibawah:
Program pecahan uang ini berfungsi untuk menentukan berapakah saja jumlah yang diperlukan untuk nominal tertentu.
Misalkan pecahan uang 150rb diinputkan maka pecahan yang dibutuhkan adalah uang 100000 satu lembar dan 50 rb 1 lembar, ok untuk lebih jelasnya kita lihat gambar dibawah:
Dan untuk source codenya dibawah :
<!Doctype html>
<html lang="en">
<head>
<title>Hitung nilai pecahan uang</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
td{
text-align:center;
}
</style>
</head>
<body>
<div class="jumbotron">
<center><h1>Menghitung uang dalam pecahan rupiah</h1></center>
</div>
<div class="container">
<center>
<div class="row">
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
<form method="POST" action="" role="form">
<div class="form-group">
<label>Masukan nilai Uang : </label>
<input type="text" name="uang" class="form-control"><br>
<input type="submit" value="inputkan" class="btn btn-default">
</div>
</form>
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
</div>
</center>
<center>
<div class="row">
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
<?php
if (!isset($_POST['uang'])){
$uang = 0;
}else{
$uang = $_POST["uang"];
}
if ($uang < 100){
echo "Uang tidak boleh kurang dari 100 rupiah";
}else {
echo "
<p>
<table class = 'table' border=0>
<tr>
<th>
Lembar
</th>
<th>
Pecahan
</th>
</tr>
";
if ( $uang >= 100000){
$nilai_uang = floor(($uang / 100000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_100rb.jpeg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 100000;
if ( $uang >= 50000 && $uang < 100000){
$nilai_uang = floor(($uang / 50000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_50rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 50000;
if ( $uang >= 20000 && $uang < 500000){
$nilai_uang = floor(($uang / 20000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_20rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 20000;
if ( $uang >= 10000 && $uang < 20000){
$nilai_uang = floor(($uang / 10000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_10rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 10000;
if ( $uang >= 5000 && $uang < 10000){
$nilai_uang = floor(($uang / 5000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_5rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 5000;
if ( $uang >= 2000 && $uang < 5000){
$nilai_uang = floor(($uang / 2000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_2rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 2000;
if ( $uang >= 1000 && $uang < 2000){
$nilai_uang = floor(($uang / 1000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_seribu.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 1000;
if ( $uang >= 500 && $uang < 1000){
$nilai_uang = floor(($uang / 500));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_500rupiah.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 500;
if ( $uang >= 200 && $uang < 5000){
$nilai_uang = floor(($uang / 200));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_200rupiah.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 200;
if ( $uang >= 100 && $uang < 2000){
$nilai_uang = floor(($uang / 100));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_100rupiah.JPG' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
echo "</table>";
}
?>
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
</div>
</div>
</center>
</div>
</html>
<html lang="en">
<head>
<title>Hitung nilai pecahan uang</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
td{
text-align:center;
}
</style>
</head>
<body>
<div class="jumbotron">
<center><h1>Menghitung uang dalam pecahan rupiah</h1></center>
</div>
<div class="container">
<center>
<div class="row">
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
<form method="POST" action="" role="form">
<div class="form-group">
<label>Masukan nilai Uang : </label>
<input type="text" name="uang" class="form-control"><br>
<input type="submit" value="inputkan" class="btn btn-default">
</div>
</form>
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
</div>
</center>
<center>
<div class="row">
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
<?php
if (!isset($_POST['uang'])){
$uang = 0;
}else{
$uang = $_POST["uang"];
}
if ($uang < 100){
echo "Uang tidak boleh kurang dari 100 rupiah";
}else {
echo "
<p>
<table class = 'table' border=0>
<tr>
<th>
Lembar
</th>
<th>
Pecahan
</th>
</tr>
";
if ( $uang >= 100000){
$nilai_uang = floor(($uang / 100000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_100rb.jpeg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 100000;
if ( $uang >= 50000 && $uang < 100000){
$nilai_uang = floor(($uang / 50000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_50rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 50000;
if ( $uang >= 20000 && $uang < 500000){
$nilai_uang = floor(($uang / 20000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_20rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 20000;
if ( $uang >= 10000 && $uang < 20000){
$nilai_uang = floor(($uang / 10000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_10rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 10000;
if ( $uang >= 5000 && $uang < 10000){
$nilai_uang = floor(($uang / 5000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_5rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 5000;
if ( $uang >= 2000 && $uang < 5000){
$nilai_uang = floor(($uang / 2000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_2rb.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 2000;
if ( $uang >= 1000 && $uang < 2000){
$nilai_uang = floor(($uang / 1000));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_seribu.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 1000;
if ( $uang >= 500 && $uang < 1000){
$nilai_uang = floor(($uang / 500));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_500rupiah.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 500;
if ( $uang >= 200 && $uang < 5000){
$nilai_uang = floor(($uang / 200));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_200rupiah.jpg' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
$uang = $uang % 200;
if ( $uang >= 100 && $uang < 2000){
$nilai_uang = floor(($uang / 100));
echo "
<tr>
<td>$nilai_uang</td>
<td><img src='images/uang_100rupiah.JPG' class='img-rounded' width='100' height='50'></td>
</tr>
";
}
echo "</table>";
}
?>
</div>
<div class="col-sm-4 col-xs-4 col-md-4 col-lg-4">
</div>
</div>
</div>
</center>
</div>
</html>
Terimakasih Semoga membantu
Subscribe to:
Posts (Atom)