Contoh Penggunakan If, Else If, dan Else.


Menentukan Penampil Gambar
HTML (Form.html)
<form action="form.php" method="post">
Jenis Roti : <select name="jenis">
<option value="tart">Tart</option>
<option value="cup">Cup</option>
</select><br>

Jumlah Roti : <select name="jumlah">
<option value="3">3</option>
<option value="6">6</option>
<option value="9">9</option>
</select><br>
Pilih Warna : <select name="warna">
<option value="red">red</option>
<option value="blue">blue</option>
</select><br>
<input type="submit">
</form>


PHP (form.php)
<?php

if (($jenis == "tart") and ($jumlah == "3") and ($warna == "red")){

echo "<img src='3red.jpg' width='100'>";
}
else if (($jenis == 'tart') and ($jumlah == '6') and ($warna == 'red')){
echo "<img src='6red.jpg' width='100'>";
}
else if (($jenis == 'tart') and ($jumlah == '9') and ($warna == 'red')){
echo "<img src='9red.jpg' width='100'>";
}
else if (($jenis == 'tart') and ($jumlah == '3') and ($warna == 'blue')){
echo "<img src='3blue.jpg' width='100'>";
}
else if (($jenis == 'tart') and ($jumlah == '6') and ($warna == 'blue')){
echo "<img src='6blue.jpg' width='100'>";
}
else if (($jenis == 'tart') and ($jumlah == '9') and ($warna == 'blue')){
echo "<img src='9blue.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '3') and ($warna == 'red')){
echo "<img src='3redcup.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '6') and ($warna == 'red')){
echo "<img src='6redcup.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '9') and ($warna == 'red')){
echo "<img src='9redcup.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '3') and ($warna == 'blue')){
echo "<img src='3bluecup.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '6') and ($warna == 'blue')){
echo "<img src='6bluecup.jpg' width='100'>";
}
else if (($jenis == 'cup') and ($jumlah == '9') and ($warna == 'blue')){
echo "<img src='9bluecup.jpg' width='100'>";
}
?>