fungsi-fungsi pendukung

KONEKSI KE DATABASE PEGAWAI

<?php
$username=”root”;
$pass=””;
$alamat=”localhost”;

$coba=mysql_connect($alamat,$username,$pass);
if(!$coba) die(“koneksi gagal”);

$select=mysql_select_db(“departemen”,$coba);
if(!$select) die(“database tidak bisa dipilih”);
?>

UNTUK MENGUBAH FORMAT TANGGAL

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

function my_ke_tgl($tanggal){
$y=substr($tanggal,0,4);
$m=substr($tanggal,5,2);
$d=substr($tanggal,8,2);

return “$d/$m/$y”;
}

function my_ke_tgl2($tanggal){
global $NAMA_BULAN;

$y=(integer) substr($tanggal,0,4);
$m=(integer) substr($tanggal,5,2);
$d=(integer) substr($tanggal,8,2);

return “$d $NAMA_BULAN[$m] $y”;
}

function tgl_ke_my($tg,$bl,$th){
$y=(int) $th;
$m=(int) $bl;
$d=(int) $tg;

return sprintf(“%04d-%02d-%02d”, $y, $m, $d);
}
?>

UNTUK MEMBUAT FORM TANGGAL DENGAN KOMBO BOX

<?php
$NAMA_BULAN=array(“”,”Januari”,”Pebruari”,”Maret”,”April”,”Mei”,”Juni”,”Juli”,”Agustus”,”September”,”Oktober”,”November”,”Desember”);

function pilihan_tanggal($tg_bawaan,$bl_bawaan,$th_bawaan){
global $NAMA_BULAN;

//Tanggal
print(“<select name=\”nama_tanggal\”>\n”);

$ada_selected=FALSE;
for($tg=1;$tg<=31;$tg++){
if($tg_bawaan==$tg){
$selected=”selected”;
$ada_selected=TRUE;
}
else
$selected=””;
print(“<option value=\”$tg\” $selected>$tg</option>\n”);
}

if($ada_selected==FALSE)
print(“<option value=\”0\” selected></option>\n”);
print(“</select>”);

//Bulan
print(“<select name=\”nama_bulan\”>\n”);

$ada_selected=FALSE;
for($bl=1;$bl<=12;$bl++){
if($bl_bawaan==$bl){
$selected=”selected”;
$ada_selected=TRUE;
}
else
$selected=””;
print(“<option value=\”$bl\” $selected>$NAMA_BULAN[$bl]</option>\n”);
}

if($ada_selected==FALSE)
print(“<option value=\”0\” selected></option>\n”);
print(“</select>\n”);

//Tahun
print(“<select name=\”nama_tahun\”>\n”);
$ada_selected=FALSE;
for($th=1900;$th<=2050;$th++){
if($th_bawaan==$th){
$selected=”selected”;
$ada_selected=TRUE;
}
else
$selected=””;
print(“<option value=\”$th\” $selected>$th</option>\n”);
}

if($ada_selected==FALSE)
print(“<option value=\”0\” selected></option>”);
print(“</select>\n”);
}

?>

UNTUK MEMBUAT HALAMAN TAMPILAN SEPERTI GOOGLE

<html>
<head>
<title>Latihan buat halaman</title>
</head>

<body>
<?php
class halaman{
var $jml_data;
var $jml_halaman;
var $jml_tiap_halaman;
var $hal_sekarang;

function halaman($jml){
$this->jml_tiap_halaman=$jml;
($this->hal_sekarang=$_GET[“page”]);
if(empty($this->hal_sekarang)){
$this->hal_sekarang=1;
}
}

function berapa_halaman($jum_account){
$this->jml_data=$jum_account;
$this->jml_halaman=ceil($this->jml_data/$this->jml_tiap_halaman);
}

function awal_data(){
$nilai_awal=(($this->hal_sekarang-1)*$this->jml_tiap_halaman);
return $nilai_awal;
}

function tampilkan_halaman(){
if($this->jml_halaman>1)
{
print(“hal : “);
for($hal=1;$hal<=$this->jml_halaman;$hal++){
if($hal==$this->hal_sekarang)
{
print(“$hal | “);
}
else
{
$skrip=$_SERVER[‘PHP_SELF’];
print(“<a href=\”$skrip?page=$hal\”>$hal | </a>”);
}
}
}
}
}

?>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s