Belajar PHP Yuk
Kali ini saya akan berbagi cara mengenerate sel tabel secara fleksibel.
Ini tampilannya :
Ini tampilan setelah digenerate :
Nah ini Source Codenya untuk html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>Table Generator Anom…</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function getmax() {
var R = parseInt(document.getElementById('RowsTotal').value);
var C = parseInt(document.getElementById('ColumnsTotal').value);
var X = parseInt(document.getElementById('CellsTotal').value);
var cellmax = document.getElementById('maxcells');
var total = 'N/A';
total = R * C;
cellmax.value = new String(total);
if (X > total)
{
alert('Limit Exceed, max cells is ' + total);
document.getElementById('CellsTotal').value = new String();
}
}
</script>
<form method="post" action="generate.php">
<p><strong>TABEL GENERATOR</strong></p>
<table width="277" border="0">
<tr>
<td width="89">Rows</td>
<td width="172"><strong>: </strong><input name="RowsTotal" type="text" id="RowsTotal" onKeyUp="getmax();" onfocus="this.select();"></td></tr>
<tr>
<td><label>Columns</label></td>
<td><strong>: </strong><input name="ColumnsTotal" type="text" id="ColumnsTotal" onKeyUp="getmax();" onfocus="this.select();"></td></tr>
<tr>
<td>Cell Total </td>
<td><strong>: </strong><input name="CellsTotal" type="text" id="CellsTotal" onKeyUp="getmax();" onFocus="this.select();"></td></tr>
<tr>
<td>Max Cells </td>
<td><strong>: </strong><input name="maxcells" type="text" id="maxcells" readonly="readonly" style="background-color:#FF6"></td></tr>
<tr>
<td><div align="center">
<input type="reset" name="Reset" value="Reset"></div></td>
<td><div align="right">
<input type="submit" name="Generate" value="Generate!"></div></td></tr>
</table>
</form>
</body>
</html>
Sedangkan ini Source Codenya untuk php-nya :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<title>Untitled Document Anom</title>
</head>
<body>
<?php
$rows = 1;
$columns = 1;
$cells = 1;
?>
<?php $rows = (int) $_POST["RowsTotal"]; ?>
<?php $columns = (int) $_POST["ColumnsTotal"]; ?>
<?php $cells = (int) $_POST["CellsTotal"]; ?>
You pick <?php echo $rows; ?> rows,<br />
You pick <?php echo $columns; ?> columns,<br />
and you need <?php echo $cells; ?> cells,<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>";
?>
</body>
</html>
Selamat Mencoba :)
0 Response to "Belajar PHP Yuk"
Posting Komentar