<?php
// Connect to the database
// Check for connection errors
if ($db->connect_errno) {
    echo $db->connect_error;
    die('Ada kesalahan');
}

$no = 0;
// Query to select records
$fil = $db->query("SELECT * 
                   FROM `pesan` 
                   WHERE `status` = 1 
                     AND `disetujui` = '1' 
                     AND `tglpakai` BETWEEN '2022-01-01' AND '2023-12-31'");


    $no = 0; // Initialize $no
    // Fetch each row and update `noskrd`
    while ($res = $fil->fetch_assoc()) {
        $no++;
        $tglpakai = $res['tglpakai'];
        echo $idpesanx = $no.'. '.$res['idpesan'].'<br />';
		$idpesan = $res['idpesan'];
        // Update query
        $c = $db->query("UPDATE `pesan` 
                         SET tgldp1 = '$tglpakai', statusdp = '1' 
                         WHERE `idpesan` = '$idpesan' ");
        
        if ($c) {
            echo 'ok';
    }		

} 

?>
