Last active
April 6, 2022 05:06
-
-
Save uluumbch/d062fb4db2f2a0a6a166fa202639e093 to your computer and use it in GitHub Desktop.
praktikum modul 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Soal 2 | seigita</title> | |
<style> | |
.tab { | |
width: 20px; | |
height: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<form action="" method="post"> | |
Tinggi :<input type="text" name="tinggi"> <br> | |
Alamat Gambar : <input type="text" name="url"> <br> | |
<input type="submit" value="cetak"> | |
</form> | |
<?php | |
$tinggi = $_POST['tinggi']; | |
$url = $_POST['url']; | |
$a = 1; | |
while ($a <= $tinggi) { | |
$b = 1; | |
while ($b < $a) { | |
echo " " . " " . " " . " " . " "; | |
$b++; | |
} | |
$c = $tinggi; | |
while ($c >= $a) { | |
echo "<img src='$url'class='tab'>"; | |
$c--; | |
} | |
echo '<br>'; | |
$a++; | |
} | |
?> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// variabel nilai yang jadi penentu form mana yang akan ditampilkan | |
if ($_SERVER["REQUEST_METHOD"] == "GET") { // bila form pertama ditekan submit maka variabel nilai diberi angka yang disubmit | |
$nilai = (int)$_GET["nilai"]; | |
} | |
if (isset($_GET['tambah'])) { | |
$nilai += 1; | |
} | |
if (isset($_GET['kurang'])) { | |
$nilai -= 1; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>soal 4</title> | |
<style> | |
.gambar { | |
width: 100px; | |
height: 100px; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
if (empty($nilai)) : ?> | |
<!-- kalau variabel nilai masih kosong maka form pertama yang ditampilkan --> | |
<form action="" method="get"> | |
Jumlah Bintang: <input type="text" name="nilai"> | |
<button type="submit" name="masuk">Masukkan Nilai</button> | |
</form> | |
<?php | |
endif; | |
if (!empty($nilai)) : // sedangkan kalau nilai sudah ada isinya maka form yang kedua yang ditampilkan | |
?> | |
jumlah bintang = <?= $nilai; ?> | |
<br> | |
<?php | |
for ($i = 0; $i < $nilai; $i++) { | |
echo "<img src='./star-image.png' class='gambar'>"; | |
} | |
?> | |
<form action="" method="get"> | |
<input type="text" name="nilai" value="<?= $nilai ?>" hidden> | |
<button type="submit" name="tambah" value="tambah">tambah</button> | |
<button type="submit" name="kurang" value="kurang">kurang</button> | |
</form> | |
<?php endif; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment