Selasa, 08 Maret 2011

Modul 6

Wah uda masuk modul 6 ya.Maap ya Teman - Teman gara2 gangguan speedy baru bisa upload ne
Studi Kasus
tampilan sebagai berikut :



Source kode untuk NO. 1
saatini.php

<html>
<head>
</head>
<body>

<?php
$bulan = array ("", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");

$hari = array ("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu");

$kode_hari = (integer) date("w");
$kode_bulan = (integer) date("m");

$tanggal = (integer) date("d");
$tahun = date("Y");
$nama_hari = $hari[$kode_hari];
$nama_bulan = $bulan[$kode_bulan];

$jam=date("H");
$menit=date(":i:s");

print("Hari $nama_hari, ");
print(" Tanggal $tanggal $nama_bulan ");
print("$tahun ");

print ("pukul $jam $menit");


function cek(){
if (date(H)>=0 && date(H)<11) {
echo "<h1>SELAMAT PAGI</h1>"; }
else if(date(H)>=11 && date(H)<15) {
echo "<h1>SELAMAT SIANG</h1>";}
else if(date(H)>=15 && date(H)<18){
echo "<h1>SELAMAT SORE</h1>";}
else if(date(H)>18 && date(H)<=24){
echo "<h1>SELAMAT MALAM</h1>";}
else {echo"WAKTU SALAH";}
}


?>

<?php
cek()
?>

<form action='tabel.php' method='post'>
<table width="500" border="0" cellspacing="4" cellpadding="3">
<tr>
<td width="152">Masukkan Jumlah Baris </td>
<td width="324">:
<input width='150' type='text' name='baris' size='15' /></td>
</tr>
<tr>
<td>Masukkan Jumlah Kolom </td>
<td>:
<input width='150' type='text' name='kolom' size='15' /></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td>
<div align="left">
<input type='submit' value='Generate'/>
</div></td>
</tr>
</table>
<p></br>
</p>
<p>&nbsp;</p>
<p></br>
</p>
</form>
</body>
</html>


Source Kode NO. 2
Untuk yang no 2 hanya script proses j karena pemangggilan uda ada di no 1
<html>
<body>
<?php
$b= $_POST['baris'];
$k= $_POST['kolom'];
if(ereg("[^0-9_-]", $b, $str))
{
echo 'Masukkan angka pada baris.';
}
elseif(ereg("[^0-9_-]", $k, $str))
{
echo 'Masukkan angka pada kolom.';
}
elseif (empty($b) || empty($k))
{
echo 'Fill in the empty fields.';
}
else {
echo "<table width='200' border='2' cellspacing='1' cellpadding='1'>";
for($i=0;$i<$b;$i++)
{
print "<tr>";
for($j=0;$j<$k;$j++)
{
print "<td> &nbsp; </td>";
}
}
print "</tr>";
echo "</table>";
}
?>
</body>
</html>


Tugas Pratikum :
NO.1
Tampilan:




Source Code :
Pada Passing By Value hasil yang ditampilkan langsung hasil dari nilai variabel yang passed tersebut
a)Passing By Value
pratikum1.php
<?php
function jumlah($nilai){
$nilai++;
}
$input=959;
jumlah($input);
echo $input;
?>

Pada Passing By Reference tidak memanipulasi salinan variabel yang passed, namun variabel itu sendiri.
Untuk membuat Passing By Reference, hal itu harus dinyatakan sebelumnya dengan ampersand (&) dalam deklarasi fungsi itu.
b)Passing By Reference
pratikum1b.php
<?php
function jumlah(&$nilai){
$nilai++;
}
$input=959;
jumlah($input);
echo $input;
?>


NO.2
Tampilan:




Source Code :
pratikum2.php

<html>
<head>
<title>Hasil</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"?>
</head>

<body>
<?php
$rows = 1;
$columns = 1;
$cells = 1;
?>


<?php $rows = (int) $_POST["RowsTotal"]; ?>
<?php $columns = (int) $_POST["ColumnsTotal"]; ?>
<?php $cells = (int) $_POST["CellsTotal"]; ?>
Anda membuat <?php echo $rows; ?> baris,
<?php echo $columns; ?> kolom,
dan cuma pake <?php echo $cells; ?> sel.<br/><br/>

<?php
$width = $columns * 80;
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>

tabel2.php
<html>
<head>
<title>Pratikum 2 Modul 6</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"?>
</head>

<body>
<form method="post" action="pratikum2.php">
<p><h2>GENERATE TABEL</h2></p>
<table width="277"? border="0"?>
<tr>
<td width="89"?>Baris</td>
<td width="172"?><strong>: </strong><input name="RowsTotal"type="text" id="RowsTotal" onFocus="this.select();"></td>
</tr>
<tr>
<td><label>Kolom</label></td>
<td><strong>: </strong><input name="ColumnsTotal" type="text" id="ColumnsTotal" onFocus="this.select();"></td>
</tr>
<tr>
<td>Jumlah Sel</td>
<td><strong>: </strong><input name="CellsTotal" type="text" id="CellsTotal" onFocus="this.select();"></td>
</tr>


<tr>
<td>
<div align="center">
<br />
<input type="reset" name="Reset" value="Reset">
</div></td>

<td>
<div align="right">
<br />
<input type="submit" name="Generate" value="Generate">
</div></td>
</tr>

</table>
</form>


</body>
</html>

Tidak ada komentar:

Posting Komentar