Statement if else pada PHP.
=============================================
Berikut script menggunakan statement if else pada PHP dan juga mengubah bilangan integer menjadi format currency (mata uang).
--------------------------------
<html>
<head>
<title> Penjualan </title>
</head>
<body>
<b>
<form method="post">
Total Harga : <input type="text" name="harga" > <br><br>
<input type="submit" value="Hitung Diskon" >
</form>
<?php
$harga = isset($_POST['harga'])?abs((int)$_POST['harga']):'';
{
if ($harga == null)
echo ("Masukkan Nilai Harga!");
elseif ($harga > 2000000)
$diskon=$harga * 0.2 ;
elseif ($harga >= 1000000)
$diskon=$harga * 0.07 ;
elseif ($harga >= 500000)
$diskon=$harga * 0.05 ;
else
$diskon=0 ;
$bayar=$harga-$diskon;
echo("Total harga = Rp. ");
echo number_format($harga,2,',','.');
echo ("<br>");
echo("Diskon Pembelian = Rp.");
echo number_format($diskon,2,',','.');
echo ("<br>");
echo("Jumlah yang Harus dibayar = Rp.");
echo number_format($bayar,2,',','.');
}
?>
</b>
</body>
</html>
<head>
<title> Penjualan </title>
</head>
<body>
<b>
<form method="post">
Total Harga : <input type="text" name="harga" > <br><br>
<input type="submit" value="Hitung Diskon" >
</form>
<?php
$harga = isset($_POST['harga'])?abs((int)$_POST['harga']):'';
{
if ($harga == null)
echo ("Masukkan Nilai Harga!");
elseif ($harga > 2000000)
$diskon=$harga * 0.2 ;
elseif ($harga >= 1000000)
$diskon=$harga * 0.07 ;
elseif ($harga >= 500000)
$diskon=$harga * 0.05 ;
else
$diskon=0 ;
$bayar=$harga-$diskon;
echo("Total harga = Rp. ");
echo number_format($harga,2,',','.');
echo ("<br>");
echo("Diskon Pembelian = Rp.");
echo number_format($diskon,2,',','.');
echo ("<br>");
echo("Jumlah yang Harus dibayar = Rp.");
echo number_format($bayar,2,',','.');
}
?>
</b>
</body>
</html>
----------------------------------------
Silahkan coba tips2 lainnya di sini. Semoga bermanfaat.
***
No comments:
Post a Comment