Pemrograman PHP 5

Struktur Kontrol (Pengkondisian)

 

Latihan 01 <<< if01.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>Latihan PHP</title>

</head>

<body>

<?

echo “***** Latihan IF Satu Kondisi ***** <p>”;

$a = 60;

$b = 70;

echo “Nilai a = $a <br>”;

echo “Nilai b = $b <p>”;

if($a<$b)

echo “Nilai a lebih kecil dari Nilai b”;

?>

</body>

</html>

Latihan 02 <<< if02.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>Latihan PHP</title>

</head>

<body>

<?

echo “***** Latihan IF Dua Kondisi ***** <p>”;

$a = 80;

$b = 70;

echo “Nilai a = $a <br>”;

echo “Nilai b = $b <p>”;

if($a<$b)

echo “Nilai a lebih kecil dari Nilai b”;

else

echo “Nilai a lebih besar dari Nilai b”;

?>

</body>

</html>

 

 

 

 

Latihan 01 <<< kasus01.php >>>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>***** FORM INPUT *****</title>

</head>

<body>

<form action = “bukti01.php” method = “get”>

<center>

<h1> RS. SEHAT SELALU </h1>

<b><i>Jl. Merdeka no.2 Bekasi Tenggara <br></i></b>

<hr color = red>

</center>

<pre>

Nama Pasien   : <input type = “text” name = “nama” size = 25 maxlength = 30><br>

Alamat Pasien : <textarea name = “alamat” rows=3 cols=30 wrap=”off”></textarea><br>

Kode Obat     : <Select size=1 name = “kdobat”>

<option> KP001

<option> TB002

<option> SR003

</select><br>

</pre>

<hr color = red>

<input type = “submit” name = “lanjut” value = “CETAK”>

&nbsp;&nbsp;&nbsp;

<input type = “reset” name = “reset” value = “BATAL”>

<hr color = red>

</form>

</body>

</html>

 

 

 

 

Latihan 02 <<< bukti01.php >>

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>***** CETAK BUKTI *****</title>

</head>

<body>

<center>

<h1> RS. SEHAT SELALU </h1>

<b><i>Jl. Merdeka no.2 Bekasi Tenggara <br></i></b>

<hr color = red>

</center>

<pre>

<?

$nama = $_GET[‘nama’];

$alamat = $_GET[‘alamat’];

$kdobat = $_GET[‘kdobat’];

if($kdobat == “KP001”)

{

$harga = 15000;

$jenis = “Kapsul”;

}

elseif($kdobat == “TB002”)

{

$harga = 18000;

$jenis = “Tablet”;

}

else

{

$harga = 20000;

$jenis = “Sirup”;

}

echo “**** TERIMA KASIH *****”;

echo “<p>”;

echo”Nama Pasien   : $nama <br>”;

echo”Alamat Pasien : $alamat <br>”;

echo”Harga Obat    : Rp. $harga <br>”;

echo”Jenis Obat    : $jenis”;

?>

</pre>

<hr color = red>

<a href = “kasus01.php”>ISI DATA LAGI</a>

</body>

</html>

Latihan 03 <<< kasus02.php >>>

 

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>***** FORM INPUT *****</title>

</head>

<body>

<form action = “bukti02.php” method = “post”>

<center>

<h1> TOKO KUE “ENAK BANGET” </h1>

<b><i>Jl. Merdeka no.3 Bekasi Timur <br></i></b>

<hr color = red>

</center>

<p>

<font face = “courier new” size = 3>

<table border = 1>

<tr>

<td colspan = 3 align = center>DAFTAR HARGA KUE</td>

</tr>

<tr>

<td>CAKE</td>

<td>Rp. 10.000,00</td>

<td rowspan = 4>

<img src = “kue.jpg” width = 100 height = 100>

</td>

</tr>

<tr>

<td>BROWNIES</td>

<td>Rp. 12.000,00</td>

</tr>

<tr>

<td>PANCAKE</td>

<td>Rp. 15.000,00</td>

</tr>

<tr>

<td>STRAWBERRY CAKE</td>

<td>Rp. 17.000,00</td>

</tr>

</table>

</font>

<pre>

<p>

Nama Pembeli    : <input type = “text” name = “nama” size = 25 maxlength = 30><br>

Alamat Konsumen : <textarea name = “alamat” rows=3 cols=30 wrap=”off”></textarea><br>

Pilih Nama Kue  : <Select size=1 name = “kue”>

<option> CAKE

<option> BROWNIES

<option> PANCAKE

<option> STRAWBERRY CAKE

</select>

<br>

Jumlah Beli     : <input type = “text” name = “jumbel” size = 25 maxlength = 30><br>

</pre>

<hr color = red>

<input type = “submit” name = “lanjut” value = “CETAK”>

&nbsp;&nbsp;&nbsp;

<input type = “reset” name = “reset” value = “BATAL”>

<hr color = red>

</form>

</body>

</html>

 

 

 

Latihan 04 <<< bukti02.php >>>

 

<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>

<html>

<head>

<title>***** CETAK BUKTI *****</title>

</head>

<body>

<center>

<h1> TOKO KUE “ENAK BANGET” </h1>

<b><i>Jl. Merdeka no.3 Bekasi Timur <br></i></b>

<hr color = red>

</center>

<pre>

<?

$nama = $HTTP_POST_VARS[‘nama’];

$alamat = $HTTP_POST_VARS[‘alamat’];

$kue = $HTTP_POST_VARS[‘kue’];

$jumbel = $HTTP_POST_VARS[‘jumbel’];

switch($kue)

{

case “CAKE” :

$harga = 10000;

break;

case “BROWNIES” :

$harga = 12000;

break;

case “PANCAKE” :

$harga = 15000;

break;

default :

$harga = 17000;

}

$total = $harga * $jumbel;

echo “**** TERIMA KASIH *****”;

echo “<p>”;

echo”Nama Konsumen   : $nama <br>”;

echo”Alamat Konsumen : $alamat <br>”;

echo”——————————————— <br>”;

echo”Kue Pesanan     : $kue <br>”;

echo”Harga Kue       : Rp. $harga <br>”;

echo”Jumlah Beli     : $jumbel <br>”;

echo”——————————————— X <br>”;

echo”Total Bayar     : Rp. $total”;

?>

</pre>

<hr color = red>

<a href = “kasus02.php”>ISI DATA LAGI</a>

</body>

</html>

 

 

 

 

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s