Quote:
|
Originally Posted by Richard M
Hi guys, I'm having one of those moments where I'm so deep in code that I can't work out what should be obvious in this case.
The following is a bit of PHP code which executes a certain function depending on if the timestamp $userlastsync is less than 1 or 2 weeks ago.
I've set $warn_time to 10 minutes for debugging purposes because it appears to be executing both functions for no apparent reason.
Both $userlastsync and $warn_time are returned as Unix timestamps.
PHP Code:
$warn_time = strtotime("-10 minutes");
$alert_time = strtotime("-2 weeks");
if ($alert_time > $userlastsync)
{
do_alert();
}
elseif ($warn_time > $userlastsync )
{
do_warn();
}
If this code right?
It looks right to me, that's the problem.
Because I've set the warn level to -10 minutes it should only be executing do_warn() based on the time given in the image in my sig.

|
Bit bizarre.....
This is my test code in full, and it seems to work fine...
PHP Code:
<?php
$warn_time = strtotime("-10 minutes");
$alert_time = strtotime("-2 weeks");
$userlastsync = strtotime("-20 minutes"); // strtotime("-3 weeks");
echo($warn_time . " --- " . $alert_time . " --- " . $userlastsync);
if ($alert_time > $userlastsync)
{
echo("<br><br>--First Clause--");
}
elseif ($warn_time > $userlastsync )
{
echo("<br><br>--Second Clause--");
}
?>
I'd replace your function calls with echos (debug statements) just in case you defined them wrong or they are being called from somewhere else. Other than that... echo your timestamps before and after changes or calls to see if they are being modded somewhere, or updated incorrectly...
I basically just pasted your code in, changed the functions to echos and set the userlastsync myself. I can only think your problem must lie outside that