Listingnya seperti dibawah ini :
<!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=iso-8859-1" />
<title>PAKAI IF</title>
</head>
<body>
<h1>Menggunakan IF</h1>
<form id="form1" name="form1" method="post" action="prosesif.php">
<table width="304" height="75" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="118" height="26" valign="top">Nama Buah </td>
<td width="8" valign="top">:</td>
<td width="230" valign="top"><select name="nama" id="nama">
<option>APEL</option>
<option>ANGGUR</option>
<option>PEAR</option>
<option>LANGSAT</option>
<option>RAMBUTAN</option>
<option>MANGGIS</option>
<option>MANGGA</option>
<option>JERUK</option>
</select></td>
</tr>
<tr>
<td height="25" valign="top">Banyaknya</td>
<td valign="top">:</td>
<td valign="top"><label>
<input name="qty" type="text" id="qty" size="4" maxlength="10" />
</label>
kg</td>
</tr>
<tr>
<td height="24" valign="top"> </td>
<td valign="top"> </td>
<td valign="top"><label>
<input name="hitung" type="submit" id="hitung" value="HITUNG" />
</label></td>
</tr>
</table>
</form>
</body>
</html>
lalu buat file baru lagi seperti dibawah ini :
dengan listing seperti dibawah ini :
<!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=iso-8859-1" />
<title>PAKAI IF</title>
</head>
<body>
<H1>Menggunakan IF</H1>
<pre>
<?php
$nama=$_POST['nama'];
$qty=$_POST['qty'];
if ($nama=="APEL")
{
$harga=12000;
}
elseif ($nama=="ANGGUR")
{
$harga=30000;
}
elseif ($nama=="PEAR")
{
$harga=20000;
}
elseif ($nama=="LANGSAT")
{
$harga=3000;
}
elseif ($nama=="RAMBUTAN")
{
$harga=5000;
}
elseif ($nama=="MANGGIS")
{
$harga=15000;
}
elseif ($nama=="MANGGA")
{
$harga=10000;
}
elseif ($nama=="JERUK")
{
$harga=10000;
}
else
{
$harga=0;
}
$bayar=$qty*$harga;
?>
</pre>
<table width="370" border="0" align="left" cellpadding="0">
<tr>
<td colspan="3"><div align="left">TOKO BUAH
<hr />
</div></td>
</tr>
<tr>
<td width="97">Jenis Buah </td>
<td width="8">:</td>
<td width="243"><?php echo $nama ; ?></td>
</tr>
<tr>
<td>Banyaknya</td>
<td>:</td>
<td><?php echo $qty ; ?> kg </td>
</tr>
<tr>
<td>Harga</td>
<td>:</td>
<td>Rp. <?php echo $harga ; ?></td>
</tr>
<tr>
<td>Jumlah Bayar </td>
<td>:</td>
<td>Rp. <?php echo $bayar ; ?></td>
</tr>
</table>
</body>
</html>
0 komentar:
Posting Komentar
Silahkan Beri Komentar... ^^