PHP ile İstenen Adette Div (Kutu) Oluşturma

sdkbyrm

webmasterfrm
Üyelik Tarihi
23 Aralık 2020
Mesajlar
813
Beğeniler
1
Ticaret: 0 / 0 / 0
Bu örneğimizde PHP ile sayfamızda kullanıcıdan aldığımız adet kadar kutu oluşturacağız. Örneğimizde kullanıcıdan adet bilgisini alacağımız bir text kutusu ve bir button oluşturacağız. Örneğimize ait html ve php kodları aşağıdaki gibi olacaktır. Tek sayı olan kutuların mavi çift olanların ise kırmızı renk olarak ayarlanmasını sağlamak için CSS kullanacağız.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>www.yazilimkodlama.com</title>
<style>
.kutu{
background-color: red;
width: 150px;
height: 150px;
margin: 5px;
float: left;
color: white;
}
.kutu1{
background-color: blue;
width: 150px;
height: 150px;
margin: 5px;
float: left;
color: white;
}
</style>
</head>
<body>
<form method="post" action="">
<input type="text" name="adet">
<input type="submit" name="olustur" value="Oluştur">
</form>
<?php
if(isset($_POST['olustur'])){
for($i=1;$i<=$_POST["adet"];$i++){
if($i%2==0){
echo '<div class="kutu">'.$i.'</div>';
}
else{
echo '<div class="kutu1">'.$i.'</div>';
}
}
}

?>
</body>
</html>
 

Ekli dosyalar

  • 1608739293341.png
    1608739293341.png
    17.6 KB · Görüntüleme: 47
Üst