Kode Autogenerate yang jumlahnya sedikit (<100):
$sql="select `kd_user` from `$tbuser` order by `kd_user` desc";
$jum= getJum($conn,$sql);
$kd="ADM";
if($jum > 0){
$d=getField($conn,$sql);
$idmax=$d['kd_user'];
$urut=substr($idmax,3,2)+1;//01
if($urut<10){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}
else{$idmax="$kd"."01";}
$kd_user=$idmax;
jadinya:
ADM01
ADM02
ADM03
dst...
Kode Autogenerate yang jumlahnya Unlimited (>100 ~):
$sql="select `kd_daftar` from `$tbdaftar` order by `kd_daftar` desc";
$q=mysqli_query($conn, $sql);
$jum=mysqli_num_rows($q);
$th=date("y");
$bl=date("m")+0;if($bl<10){$bl="0".$bl;}
$kd="REG".$th.$bl;
if($jum > 0){
$d=mysqli_fetch_array($q);
$idmax=$d["kd_daftar"];
$bul=substr($idmax,5,2);
$tah=substr($idmax,3,2);
if($bul==$bl && $tah==$th){
$urut=substr($idmax,7,3)+1;
if($urut<10){$idmax="$kd"."00".$urut;}
else if($urut<100){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}//==
else{
$idmax="$kd"."001";
}
}//jum>0
else{$idmax="$kd"."001";}
$kd_daftar=$idmax;
dst...
Kode Autogenerate yang jumlahnya Unlimited (>100 ~):
$sql="select `kd_daftar` from `$tbdaftar` order by `kd_daftar` desc";
$q=mysqli_query($conn, $sql);
$jum=mysqli_num_rows($q);
$th=date("y");
$bl=date("m")+0;if($bl<10){$bl="0".$bl;}
$kd="REG".$th.$bl;
if($jum > 0){
$d=mysqli_fetch_array($q);
$idmax=$d["kd_daftar"];
$bul=substr($idmax,5,2);
$tah=substr($idmax,3,2);
if($bul==$bl && $tah==$th){
$urut=substr($idmax,7,3)+1;
if($urut<10){$idmax="$kd"."00".$urut;}
else if($urut<100){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}//==
else{
$idmax="$kd"."001";
}
}//jum>0
else{$idmax="$kd"."001";}
$kd_daftar=$idmax;
jadinya:
REG1903001
REG1903002
REG1903003
...
REG1904001
REG1904002
REG1904003
...
REG2001001
REG2001002
...
Konversi Tanggal ke Hari:
$tgl="2019-03-01";
$dayofweek = date('l', strtotime($tgl));//w =angka, l=nama hari dalam inggris
$hari="Senin";
if($dayofweek=="Sunday"){$hari="Minggu";}
else if($dayofweek=="Monday"){$hari="Senin";}
else if($dayofweek=="Tuesday"){$hari="Selasa";}
else if($dayofweek=="Wednesday"){$hari="Rabu";}
else if($dayofweek=="Thrusday"){$hari="Kamis";}
else if($dayofweek=="Friday"){$hari="Jumat";}
else if($dayofweek=="Saturday"){$hari="Sabtu";}
Konvversi Tanggal ke YMD
function BAL($tanggal){
$arr=split(" ",$tanggal);
if($arr[1]=="Januari" || $arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari" || $arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret" || $arr[1]=="March"){$bul="03";}
else if($arr[1]=="April" || $arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei" || $arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni" || $arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli" || $arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus" || $arr[1]=="August"){$bul="08";}
else if($arr[1]=="September" || $arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober" || $arr[1]=="October"){$bul="10";}
else if($arr[1]=="November" || $arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember" || $arr[1]=="November"){$bul="11";}
else if($arr[1]=="Desember" || $arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
Konversi YMD ke Indonesia
function WKT($sekarang){
$tanggal = substr($sekarang,8,2)+0;
$bulan = substr($sekarang,5,2);
$tahun = substr($sekarang,0,4);
$judul_bln=array(1=> "Januari", "Februari", "Maret", "April", "Mei","Juni", "Juli", "Agustus", "September","Oktober", "November", "Desember");
$wk=$tanggal." ".$judul_bln[(int)$bulan]." ".$tahun;
return $wk;
}
Konversi Nominal Ke Rupiah:
<?php function RP($rupiah){return number_format($rupiah,"2",",",".");}?>
AJAX
Artinya:
saat saya pilih tanggal 13 maret 2019, lalu pilih klinik Umum, maka
pilihan jadwal yang dimunculkan hanyalah
data semua jadwal yang ada di hari tsb ( 13 maret 2019= SABTU), dan klinik yang di sediakan hanya yang kategori UMUM.
<script type="text/javascript">
var xmlHttp
function showKlinik(str){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser tidak support HTTP Request")
return
}
var tgl=document.getElementById("tanggal_periksa").value;
var url="getjadwal.php"
url=url+"?q="+str+"&tgl="+tgl+"&ket=ok"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=SC1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function SC1() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{xmlHttp=new XMLHttpRequest();}
catch (e){
try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
}
return xmlHttp;
}
</script>
PADA GUI/ LAYOUT:
<select class="form-control" name="klinik" id="klinik" onChange="showKlinik(this.value)">
<option>Pilih Klinik</option>
<option value="Umum" <?php if($klinik=="Umum"){echo"selected";}?>>Umum</option>
<option value="Gigi" <?php if($klinik=="Gigi"){echo"selected";}?>>Gigi</option>
</select>
<div id="txtHint">
<select class="form-control" name="kd_jadwal" id="kd_jadwal">
<option>Pilih Jadwal</option>
<?php
$s="select * from `tb_jadwal`";
$q=getData($conn,$s);
foreach($q as $d){
$kd_jadwal0=$d["kd_jadwal"];
$jadwal=$d["hari"]." | ".$d["jam"];
echo"<option value='$kd_jadwal0' ";if($kd_jadwal0==$kd_jadwal){echo"selected";} echo">$kd_jadwal0 - $jadwal </option>";
}
?>
</select>
</div>
+++++++++++++++++++++++++++++++++++++++++++++
getjadwal.php
<?php
date_default_timezone_set("Asia/Jakarta");
date_default_timezone_set("Asia/Jakarta");
require_once"konmysqli.php";
$q=$_GET["q"];
$tgl=BAL($_GET["tgl"]);
$dayofweek = date('l', strtotime($tgl));//w l
$hari="Senin";
if($dayofweek=="Sunday"){$hari="Minggu";}
else if($dayofweek=="Monday"){$hari="Senin";}
else if($dayofweek=="Tuesday"){$hari="Selasa";}
else if($dayofweek=="Wednesday"){$hari="Rabu";}
else if($dayofweek=="Thrusday"){$hari="Kamis";}
else if($dayofweek=="Friday"){$hari="Jumat";}
else if($dayofweek=="Saturday"){$hari="Sabtu";}
?>
<select class="form-control" name="kd_jadwal" id="kd_jadwal">
<option>Pilih Jadwal <?php echo $hari;?></option>
<?php
$s="select * from `tb_jadwal` where klinik='$q' and hari='$hari'";
$q=getData($conn,$s);
foreach($q as $d){
$kd_jadwal0=$d["kd_jadwal"];
$jadwal=$d["jam"];
$dokter=getDokter($conn,$d["nip_dokter"]);
echo"<option value='$kd_jadwal0' ";echo">$jadwal :$dokter </option>";
}
?>
</select>
<?php
function getDokter($conn,$kode){
$field="nama_dokter";
$sql="SELECT `$field` FROM `tb_dokter` where `nip_dokter`='$kode'";
$rs=$conn->query($sql);
$rs->data_seek(0);
$row = $rs->fetch_assoc();
$rs->free();
return $row[$field];
}
function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
// echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}
?>
<?php
function BAL($tanggal){
$arr=split(" ",$tanggal);
if($arr[1]=="Januari" || $arr[1]=="January"){$bul="01";}
else if($arr[1]=="Februari" || $arr[1]=="February"){$bul="02";}
else if($arr[1]=="Maret" || $arr[1]=="March"){$bul="03";}
else if($arr[1]=="April" || $arr[1]=="April"){$bul="04";}
else if($arr[1]=="Mei" || $arr[1]=="May"){$bul="05";}
else if($arr[1]=="Juni" || $arr[1]=="June"){$bul="06";}
else if($arr[1]=="Juli" || $arr[1]=="July"){$bul="07";}
else if($arr[1]=="Agustus" || $arr[1]=="August"){$bul="08";}
else if($arr[1]=="September" || $arr[1]=="September"){$bul="09";}
else if($arr[1]=="Oktober" || $arr[1]=="October"){$bul="10";}
else if($arr[1]=="November" || $arr[1]=="November"){$bul="11";}
else if($arr[1]=="Nopember" || $arr[1]=="November"){$bul="11";}
else if($arr[1]=="Desember" || $arr[1]=="December"){$bul="12";}
return "$arr[2]-$bul-$arr[0]";
}
?>
Tidak ada komentar:
Posting Komentar