I'm doing some verifications for a telegram bot that I'm testing, always the first "else if" is executed when it should not be, for example: I have a client whose payday is the 24th of this month, then, five days before the bot sends you a warning (first if it is executed correctly), the problem is that after executing the last else if (both dates coincide, because today is 19 and another customer pays the 19), carries out this warning, but after a couple of minutes, the first else if is executed, which should not be the case, since in this case, the if evaluates, among other things, that the current date is not equal to the payment date (same date) , nevertheless, it is executed and the value of both variables is different. Any idea?
Thank you very much in advance.
// code fragment
$sql2 = "SELECT id, fecha_pago, notified FROM clients";
$result3 = $conn->query($sql2);
while ($row = mysqli_fetch_array($result3, MYSQLI_ASSOC)) {
$val1 = $row["id"];
$val4 = $row["fecha_pago"];
$val3 = $row["notified"];
$val4ToTime = strtotime($val4) - time();
$val4t2 = strtotime($val4. '-5 days') - time();
$dateRm = strtotime($dateR) - time();
$val4mod = date("d-m-Y", strtotime($val4));
if ($dateRm == $val4t2 && $val3 != 's') {
$messNotif = "Te quedan 5 días de suscripción!, fecha fin de suscripción: ".$val4mod;
sendMessage($val1, $messNotif);
sendMessage($groupNotif, $dateRm);
sendMessage($groupNotif, $val4t2);
$sql2 = "UPDATE clients SET notified = 's' WHERE 'clients'.'id' = ".$val1;
$result = $conn->query($sql2);
} else if ($dateRm != $val4t2 && $dateRm != $val4ToTime && $val3 == 's'){
sendMessage($groupNotif, $dateRm);
sendMessage($groupNotif, $val4ToTime);
$sql2 = "UPDATE clients SET notified = 'n' WHERE 'clients'.'id' = ".$val1;
$result = $conn->query($sql2);
} else if ($dateRm == $val4ToTime && $val3 == 'n') {
// $messNotif = "Se te ha acabado la suscripción!, para renovarla, utiliza el comando /paypal y notifica a @pepe ";
//sendMessage($val1, $messNotif);
//$sql2 = "UPDATE clients SET notified = 's' WHERE 'clients'.'id' = ".$val1;
$result = $conn->query($sql2);
}
}