Selasa, 08 Maret 2011

DASAR-DASAR PHP

Fungsi Greeting yang Menerima Argumen Integer Jam


Source Kodenya:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Fungsi Greeting</title>
</head>
<body background = "2.jpg">

<center>

<h1>
<?php
function greeting()
{
$date = date ("G : i A");
if ($date>=0 and $date<10) {
echo "Selamat Pagi";
}
else if ($date>=10 and $date<15) {
echo "Selamat Siang";
}
 else if ($date>=15 and $date<19) {
echo "Selamat Sore";
}
else if ($date>=19 and $date<00) {
echo "Selamat Malam";
}
else echo "Waktu salah)";
}
?>
<?php greeting(); ?><br>

</h1>
<h2><font color = "Green"> SELAMAT DATANG DI SITUS PENDTIUM </font></h2>

<h3><font color = "Green"> JURUSAN TEKNIK ELEKTRO </font></h3>

<h4><font color = "Red"> Sekarang adalah

<?php

//Array Hari
$array_hari = array(1=>"Senin","Selasa","Rabu","Kamis","Jumat", "Sabtu","Minggu");
$hari = $array_hari[date("N")];
//Format Tanggal
$tanggal = date ("j");
//Array Bulan
$array_bulan = array(1=>"Januari","Februari","Maret", "April", "Mei", "Juni","Juli","Agustus","September","Oktober", "November","Desember");
$bulan = $array_bulan[date("n")];
//Format Tahun
$tahun = date("Y");
//Menampilkan hari dan tanggal
echo "hari $hari, tanggal $tanggal $bulan $tahun";
?>
<br>

Waktu menunjukkan pukul:
<?php
//penulisan waktu
$date = date ("G : i A");
echo "$date WIB";
?>

</font>
</h4>
</body>

</html>


Hasilnya:




Men-generate Sel Tabel Secara Fleksibel


Sebelumnya kita menuliskan source kode dengan nama tugas2.php
Source Kodenya:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Generate Tabel</title>
</head>
<body background = "bg.jpg">
<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>Anda Memilih</strong> <?php echo $rows; ?> <em>rows,</em><br />
<strong>Anda Memilih</strong> <?php echo $columns; ?> <em>columns,</em><br />
<strong>Anda 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>



Selanjutnya kita menuliskan source kode yang kedua
Source Kodenya:


<!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: 284px;
top: 189px;
}
.style1 {
color: red;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form method="post" action="tugas2.php">
<h3 align="center" class="style1"><font color = "green" size = "14">Generate Table</font></h3>
<div align="center">
<table width="327" border="1" bgcolor = "orange">
<tr>
<td width="121" style="text-align:center"><font color = "red">Baris</font></td>
<td width="196"><strong>= </strong>
<input name="JumlahRow" type="text" id="JumlahRow" onKeyUp="getmax();" onfocus="this.select();"></td>
</tr>
<tr>
<td style="text-align:center"><label><font color = "red">Kolom</font></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"><font color = "red">Cell Total</font></td>
<td><strong>= </strong>
<input name="JumlahCell" type="text" id="JumlahCell" onKeyUp="getmax();" onFocus="this.select();"></td>
</tr>
<tr>
<td style="text-align:center"><font color = "red">Cells Maksimum</font></td>
<td><strong>= </strong>
<input name="maxcells" type="text" id="maxcells" disabled="disabled" style="text-align:center"></td>
</tr>
</table>
</div>
<div id="apDiv1">
<br/>
<br/>
<br/>
<input type="submit" name="Generate" value="Generate..!!">
<input type="reset" name="Reset" value="Reset..!!">
</div>
</form>
</body>
<script language="JavaScript" type="text/javascript">
<!--
function getmax() {
var R = parseInt(document.getElementById('JumlahRow').value);
var C = parseInt(document.getElementById('JumlahColum').value);
var X = parseInt(document.getElementById('JumlahCell').value);
var cellmax = document.getElementById('maxcells');
var total = 'N/A';
total = R * C;
cellmax.value = new String(total);
if (X > total)
{
alert('Cell Total Yang Anda Masukkan Terlalu Besar, Nilai Maksimum Cells = ' + total);
document.getElementById('CellsTotal').value = new String();
}
}
//-->
</script>
</html>



Hasilnya:











Selasa, 01 Maret 2011

DHTML dan JAVASCRIPT

Membuat Kalkulator Sederhana

Source Kodenya :
<html>

<title>KalkulatorKu</title>
<script language="JavaScript">
window.defaultStatus=

function tambah()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.hasil.value=c
}

function kurang()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.hasil.value=c
}

function kali()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.hasil.value=c
}

function bagi()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.hasil.value = c
}

function pangkat()
{
a=eval(form.a.value)
b=eval(form.b.value)
c=Math.pow(a, b)
form.hasil.value = c
}

function RESET()
{
form.a.focus()
form.a.value=""
form.b.value=""
form.hasil.value=""

}

</SCRIPT>
<body onload=kosong()>
<RIGHT>
<hr width = "500" align="left"; />
<h1><strong><font color="Green"> <font size="5"> Kalkulator Sederhana Dengan Java Script</strong></font></h1>
<hr width = "500" align="left"; />

<FORM name="form">
<pre>
<font color="red">Input 1 : </font>
<br/>
<input type="text" name="a">
<br/>
<font color="red">Input 2 : </font>
<br/>
<input type="text" name="b">


</pre>

<input type="button" value=" + " onClick="tambah()">
<input type="button" value=" - " onClick="kurang()">
<input type="button" value=" x " onClick="kali()">
<input type="button" value=" / " onClick="bagi()">
<input type="button" value=" ^ " onClick="pangkat()"><br>

<br/>
<br/>
<font color="red">Hasil : </font>
<br/>
<input type "text" name="hasil" disabled="true">
<br/>
<br/>
<input type="button" value=" Bersihkan! " onClick="RESET()">
<br/>
<br/>
<hr width = "500" align="left"; />
<br/>
<br/>
<font color="grey">::Tampilan Kalkulator Sederhana Menggunakan Java Script:: </font>
</FORM>
</RIGHT>

</body>
</html>

Hasinya:







Membuat Form Pemesanan Makanan Berbasis JAVASCRIPT

Source Kodenya:
<em><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">

<head>
<title>Form Pemesanan</title>

<script language="JavaScript" type="text/JavaScript">

<!--
function hitung() {
var myForm = document.form1;
var hargaBakso = parseInt(myForm.bakso.value) * parseInt(myForm.pesanbakso.value);
var hargaSoto = parseInt(myForm.soto.value) * parseInt(myForm.pesansoto.value);
var hargaMie = parseInt(myForm.mie.value) * parseInt(myForm.pesanmie.value);
var hargaDegan = parseInt(myForm.degan.value) * parseInt(myForm.pesandegan.value);
var hargaCampur = parseInt(myForm.campur.value) * parseInt(myForm.pesancampur.value);

var hargaTotal= hargaBakso + hargaSoto + hargaMie + hargaDegan + hargaCampur;

if(hargaTotal>50000)
{
myForm.total.value = hargaTotal;
myForm.diskon.value = 10000;
myForm.bayar.value = hargaTotal - parseInt(myForm.diskon.value);
}
else
{
myForm.total.value = hargaTotal;
myForm.diskon.value = 0;
myForm.bayar.value = hargaTotal;
}
}

function hapus(){
document.form1.reset();
}

//-->

</script>
</head>

<body background="bg.jpg">
<h2 align="center"><--Warung Sederhana--></h2>
<form name = "form1" action="#">
<table border="1" align="center">

<tr>
<td width="30" align="center" bgcolor="white">
<strong>No</strong>
</td>

<td width="150" align="center" bgcolor="white">
<strong>Makanan/Minuman</strong>
</td>

<td width="165" align="center" bgcolor="white">
<strong>Harga</strong>
</td>

<td width="150" align="center" bgcolor="white">
<strong>Pesan</strong>
</td>
</tr>

<tr>
<td align="center" bgcolor="white">1</td>
<td bgcolor="white">Bakso Istimewa</td>
<td bgcolor="white">@<input type="text" name="bakso" value="12000" disabled="true"/></td>
<td bgcolor="white"><input type="text" name="pesanbakso" value="0" onkeyup="hitung()" /></td>
</tr>

<tr>
<td align="center" bgcolor="white">2</td>
<td bgcolor="white">Soto Spesial</td>
<td bgcolor="white">@<input type="text" name="soto" value="10000" disabled="true"/></td>
<td bgcolor="white"><input type="text" name="pesansoto" value="0" onkeyup="hitung()"/></td>
</tr>

<tr>
<td align="center" bgcolor="white">3</td>
<td bgcolor="white">Mie Ayam Super</td>
<td bgcolor="white">@<input type="text" name="mie" value="15000" disabled="true"/></td>
<td bgcolor="white"><input type="text" name="pesanmie" value="0" onkeyup="hitung()"/></td>
</tr>

<tr>
<td align="center" bgcolor="white">4</td>
<td bgcolor="white">Es Degan</td>
<td bgcolor="white">@<input type="text" name="degan" value="5000" disabled="true"/></td>
<td bgcolor="white"><input type="text" name="pesandegan" value="0" onkeyup="hitung()"/></td>
</tr>

<tr>
<td align="center" bgcolor="white">5</td>
<td bgcolor="white">Es Campur</td>
<td bgcolor="white">@<input type="text" name="campur" value="7000" disabled="true"/></td>
<td bgcolor="white"><input type="text" name="pesancampur" value="0" onkeyup="hitung()"/></td>
</tr>

<tr>
<td colspan="3" align="right" bgcolor="white">Jumlah Total</td>
<td bgcolor="white"><input type="text" name="total" style="text-align:right" disabled="true"/></td>
</tr>

<tr>
<td colspan="3" align="right" bgcolor="white">Diskon</td>
<td bgcolor="white"><input type="text" name="diskon" style="text-align:right" disabled="true"/></td>
</tr>

<tr>
<td colspan="3" align="right" bgcolor="white">Jumlah Dibayar</td>
<td bgcolor="white"><input type="text" name="bayar" style="text-align:right" disabled="true"/></td>
</tr>

</table>
<br />

<input type="button" value="HAPUS" onclick="hapus()" style="position:absolute; width:75px; height:30px; margin-left: 410px; top: 340px;" />
<br/>
<br/>
<br/>
<img src = "stroberi.png" width = "200" height = "150" style="margin-left: 410px;" />

</form>
</body>
</html></em>

Hasilnya: