Friday, July 6, 2012

CODE MEMBUAT TABLE

 MEMBUAT TABLE FLEKSIBEL

1. Instal Wamp Server
2.Coding

Buat file php seperti di bawah ini
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Hasil Generate Tabel</title>
</head>
<body>
<div align=”center”>
<?php
$rows = 1;
$columns = 1;
$cells = 1;
?>
<?php $rows = (int) $_POST["JumlahRow"]; ?>
<?php $columns = (int) $_POST["JumlahColum"]; ?>
<?php $cells = (int) $_POST["JumlahCell"]; ?>
<strong>Kamu Memilih</strong> <?php echo $rows; ?> <em>rows,</em><br />
<strong>Kamu Memilih</strong> <?php echo $columns; ?> <em>columns,</em><br />
<strong>Dan Anda Membutuhkan</strong> <?php echo $cells; ?> <em>cells,</em><br />
<br />
<br />
<?php
$width = $columns * 75;
echo “<table width=”.$width.” border=1>”;
$rw = 0;
$cel = 1;
while ($rw < $rows && $cel <= $cells)
{
echo “<tr>”;
$cl = 0;
while ($cl < $columns)
{
if ($cel <= $cells)
{
echo “<td><div align=center>”.$cel.”</div></td>”;
$cel++;
}
$cl++;
}
echo “</tr>”;
$rw++;
}
echo “</table>”;
?>
</div>
</body>
</html>
Simpan Dengan Nama tabelfleksibel.php
Coding File Htmlnya untuk memanggil fungsi
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Generate Table</title>
<style type=”text/css”>
<!–
#apDiv1 {
position:absolute;
width:178px;
height:24px;
z-index:1;
left: 600px;
top: 189px;
}
.style1 {
color: #0000CC;
font-weight: bold;
}
–>
</style>
</head>
<script language=”JavaScript” type=”text/javascript”>
<!–
function getmax() {
var X = parseInt(document.getElementById(‘JumlahRow’).value);
var Y = parseInt(document.getElementById(‘JumlahColum’).value);
var Z = parseInt(document.getElementById(‘JumlahCell’).value);
var cellmax = document.getElementById(‘maxcells’);
var total = ‘N/A’;
total = X * Y;
cellmax.value = new String(total);
if (Z > total)
{
alert(‘Cell Total Yang Anda Masukkan Terlalu Besar, Nilai Maksimum Cells = ‘ + total);
document.getElementById(‘CellsTotal’).value = new String();
}
}
//–>
</script>
<body background=”back2.jpg”>
<form method=”post” action=”tabelfleksibel.php”>
<h3 align=”center”>Tabel Fleksibel Dengan Generate Table</h3>
<div align=”center”>
<table width=”300″ border=”0″ bgcolor=”#FFFFFF”>
<tr>
<td width=”120″ style=”text-align:center”>Rows</td>
<td width=”200″><strong>= </strong>
<input name=”JumlahRow” type=”text” id=”JumlahRow” onKeyUp=”getmax();” onfocus=”this.select();”></td>
</tr>
<tr>
<td style=”text-align:center”><label>Columns</label></td>
<td><strong>= </strong>
<input name=”JumlahColum” type=”text” id=”JumlahColum” onKeyUp=”getmax();” onfocus=”this.select();”></td>
</tr>
<tr>
<td style=”text-align:center”>Cell Total </td>
<td><strong>= </strong>
<input name=”JumlahCell” type=”text” id=”JumlahCell” onKeyUp=”getmax();” onFocus=”this.select();”></td>
</tr>
<tr>
<td style=”text-align:center”>Max Cells </td>
<td><strong>= </strong>
<input name=”maxcells” type=”text” id=”maxcells” disabled=”disabled” style=”text-align:center”></td>
</tr>
</table>
</div>
<div id=”apDiv1″>
<input type=”submit” name=”Generate” value=”Process”>&nbsp&nbsp&nbsp&nbsp<input type=”reset” name=”Reset” value=”Reset”>
</div>
</form>
</body>
</html>

0 comments:

Post a Comment

KOMENTAR