Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- USE test;
- CREATE TABLE IF NOT EXISTS tb_karyawan(
- nik VARCHAR(10) NOT NULL PRIMARY KEY,
- nama VARCHAR(30) NOT NULL
- ) ENGINE=MyISAM;
- INSERT INTO tb_karyawan
- VALUES
- ('123456789','Dika Nanda'),
- ('1234567890','Andika Dwi Chahya'),
- ('2147483647','Akbar Alifian');
- CREATE TABLE IF NOT EXISTS tb_presensi(
- nik VARCHAR(10) NOT NULL,
- tanggal DATE,
- jam_masuk TIME,
- jam_pulang TIME,
- terlambat TIME,
- ket VARCHAR(30) NOT NULL
- ) ENGINE=MyISAM;
- INSERT INTO tb_presensi
- VALUES
- ('123456789','2014-10-15','11:30:17','00:00:00','03:30:00','masuk'),
- ('1234567890','2014-10-11','12:25:01','12:26:27','04:25:00','masuk'),
- ('1234567890','2014-10-12','15:02:42','00:00:00','07:02:00','masuk'),
- ('1234567890','2014-10-14','09:48:47','10:42:53','01:48:00','masuk');
- */
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- $sql='SELECT nik,nama FROM tb_karyawan';
- $result=$db->query($sql);
- $karyawan=array();
- while($data=$result->fetch_assoc()){
- $karyawan[]=$data;
- }
- $sql='SELECT nik,tanggal,jam_masuk,jam_pulang,terlambat,ket FROM tb_presensi ORDER BY tanggal';
- $result=$db->query($sql);
- $presensi=array();
- $tanggal=array();
- while($data=$result->fetch_assoc()){
- if(isset($presensi[$data['tanggal']])){
- $presensi[$data['tanggal']][$data['nik']]=$data;
- }else{
- $presensi[$data['tanggal']]=array();
- $presensi[$data['tanggal']][$data['nik']]=$data;
- }
- $tanggal[]=$data['tanggal'];
- }
- $min_date=min($tanggal);
- $max_date=max($tanggal);
- echo "<table border='1'>";
- echo "<tr><th>No</th>";
- echo "<th>Tanggal</th>";
- echo "<th>NIK</th>";
- echo "<th>Nama</th>";
- echo "<th>Jam Masuk</th>";
- echo "<th>Jam Pulang</th>";
- echo "<th>Terlambat</th>";
- echo "<th>Keterangan</th></tr>";
- $i=0;
- while($min_date<=$max_date){
- foreach($karyawan as $k){
- echo "<tr><td>".(++$i)."</td>";
- echo "<td>{$min_date}</td>";
- echo "<td>{$k['nik']}</td>";
- echo "<td>{$k['nama']}</td>";
- if(isset($presensi[$min_date][$k['nik']])){
- echo "<td>{$presensi[$min_date][$k['nik']]['jam_masuk']}</td>";
- echo "<td>{$presensi[$min_date][$k['nik']]['jam_pulang']}</td>";
- echo "<td>{$presensi[$min_date][$k['nik']]['terlambat']}</td>";
- echo "<td>{$presensi[$min_date][$k['nik']]['ket']}</td>";
- }else{
- echo "<td>-</td>";
- echo "<td>-</td>";
- echo "<td>-</td>";
- echo "<td>tidak masuk</td>";
- }
- echo "</tr>";
- }
- $min_date=date('Y-m-d',strtotime($min_date.'+1 day'));
- }
- echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement