Berikut contoh salah satu untuk membuat Kode Otomatis (auto generate Code) dari system
$sql_isi ="SELECT * FROM permohonan_cuti";
$qr_isi =mysql_query($sql_isi, $koneksi) or die ("Gagal query".mysql_error());
if (mysql_num_rows($qr_isi) <=0) {
$kd_pcuti="PC001";
}
else {
$sql_kdpcuti="SELECT MAX(RIGHT(kd_pcuti,3)) + 1 AS kd_pcuti_baru FROM permohonan_cuti";
$qr_kdpcuti=@mysql_query($sql_kdpcuti) or die ("Gagal query".mysql_error());
$hs_kdpcuti=mysql_fetch_array($qr_kdpcuti) or die ("Hasil pemakai tidak ada");
$kd_pcuti_baru=$hs_kdpcuti[kd_pcuti_baru];
if ($kd_pcuti_baru < 10 ) {
$kd_pcuti="PC00".$kd_pcuti_baru;
}
elseif ($kd_pcuti_baru < 100) {
$kd_pcuti="PC0".$kd_pcuti_baru;
}
elseif ($kd_pcuti_baru < 1000) {
$kd_pcuti="PC".$kd_pcuti_baru;
}
}
Friday, January 01, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment