Pemrograman Web Dinamis
Menampilkan data keluarga sebanyak n inputan
Source Code
data.php
<?php
session_start();
$_SESSION['ALDI']=0;
header("location;index.php")
?>
index.php
<html>
<head>
<title>form index</title>
</head>
<tr><td><b><font face="Times new Rowman">Biodata</font></b></td></tr>
<form action="index.php" method="post">
<input type="text" name="LISTIA" placeholder="Nama">
<input type="text" name="DIMAS" placeholder="Alamat">
<br><input type="submit" value="Simpan"></br>
</form>
<table>
<tr><td>Nama</td><td>Alamat</td></tr>
<?php
session_start();
if(isset($_POST['LISTIA'])){
$_SESSION['LISTIA'][$_SESSION['ALDI']][0]=$_POST['LISTIA'];
$_SESSION['DIMAS'][$_SESSION['ALDI']][1]=$_POST['DIMAS'];
$_SESSION['ALDI']++;
}
for($i=1;$i<$_SESSION['ALDI'];$i++){
echo "<tr><td>".$_SESSION['LISTIA'][$i][0]."</td>";
echo "<td>".$_SESSION['DIMAS'][$i][1]."</td></tr>";
}
?>
</table>
</html>
Output
Biodata
Program Biodata Menggunakan PHP
Cara 1
<?php
echo "Biodata Teman<br><br>";
$nama1 = "Aldi";
$nama2 = "Ubai";
$nama3 = "Zaky";
$nama4 = "Andi";
$nama5 = "Bram";
$alamat1 = "Sumatera";
$alamat2 = "Lampung";
$alamat3 = "Magelang";
$alamat4 = "Kalimantan";
$alamat5 = "Kediri";
echo "Nama : ".$nama1."<br>";
echo "Alamat : ".$alamat1."<br><br>";
echo "Nama : ".$nama2."<br>";
echo "Alamat : ".$alamat2."<br><br>";
echo "Nama : ".$nama3."<br>";
echo "Alamat : ".$alamat3."<br><br>";
echo "Nama : ".$nama4."<br>";
echo "Alamat : ".$alamat4."<br><br>";
echo "Nama : ".$nama5."<br>";
echo "Alamat : ".$alamat5."<br>";
?>
Cara 2
<?php
echo "Biodata Teman<br><br>";
$nama[0] = "Aldi";
$nama[1] = "Ubai";
$nama[2] = "Zaky";
$nama[3] = "Andi";
$nama[4] = "Bram";
$alamat[0] = "Sumatera";
$alamat[1] = "Lampung";
$alamat[2] = "Magelang";
$alamat[3] = "Kalimantan";
$alamat[4] = "Kediri";
for ($i=0;$i<=4;$i++){
echo "Nama : ".$nama[$i]. "<br>";
echo "Alamat : ".$alamat[$i]. "<br><br>";
}
?>
Cara 3
<?php
echo "Biodata Teman<br><br>";
$nama = array("Aldi","Ubai","Zaki","Andi","Bram");
$alamat = array("Sumatera","Lampung","Magelang","Kalimantan","Kediri");
for ($i=0;$i<=4;$i++){
echo "Nama : ".$nama[$i]."<br>";
echo "Alamat : ".$alamat[$i]."<br><br>";
}
?>
Output
Langganan:
Postingan
(
Atom
)
Tidak ada komentar :
Posting Komentar