<?php
include "koneksi.php";
$q = "SELECT * FROM data_karyawan"; 
$res = mysqli_query($conn, $q);
$no= 1;
while($row = mysqli_fetch_array($res))
{
	echo "nomer.".$no++." : ";
	$tanggal = $row['tanggal_masuk'];
	$tanggal = new DateTime($tanggal); 

	$sekarang = new DateTime();
	//echo "sekarang : " . str_replace($sekarang);
	$perbedaan = $tanggal->diff($sekarang);

	//gabungkan
	echo $perbedaan->y .' selisih tahun.'.'</br>';
	if($perbedaan->y==7)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id']; 
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 7 tahun";
	}
	else if($perbedaan->y==14)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id'];
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 14 tahun";
	}
	else if($perbedaan->y==21)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id'];
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 21 tahun";
	}
	else if($perbedaan->y==28)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id'];
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 28 tahun";
	}
	else if($perbedaan->y==34)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id'];
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 34 tahun";
	}
	else if($perbedaan->y==46)
	{
		$s = "UPDATE data_karyawan SET sisa_cuti_besar = '1' WHERE id=" . $row['id'];
		echo $s;
		$result = mysqli_query($conn, $s);
        
        if($result)
        {
			echo "update berhasil cuti besar";
		}
		else
		{
			echo "gagal update cuti besar";
		}
		echo "perbedaan : ".$perbedaan->y . "</br>";
		echo "udah 46 tahun";
	}
}
?>