Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   Help with something that should be obvious... (https://www.cableforum.uk/board/showthread.php?t=25926)

Richard M 19-03-2005 12:46

Help with something that should be obvious...
 
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.
:help:

punky 19-03-2005 13:39

Re: Help with something that should be obvious...
 
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.
:help:


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

greencreeper 19-03-2005 13:49

Re: Help with something that should be obvious...
 
I would expect that the else precludes do_warn() from being executed - it acts as an XOR. I.e. either do_alert() or do_warn() will be executed but not both. I can't remember if PHP treats it this way though. I would also check on the comparision - is the interpretor actually comparing time or is it comparing strings, integers, or something else?

Richard M 19-03-2005 14:04

Re: Help with something that should be obvious...
 
No it is time strings.
I think it may actually be working correctly now, I just probably confused myself when I was coding it because the warning/alert functions send mail so I was receiving email for both that had been delayed for a while.

greencreeper 19-03-2005 15:06

Re: Help with something that should be obvious...
 
Quote:

Originally Posted by Richard M
No it is time strings.
I think it may actually be working correctly now, I just probably confused myself when I was coding it because the warning/alert functions send mail so I was receiving email for both that had been delayed for a while.

Sorry but I have to :D

I miss programming :(

Richard M 19-03-2005 15:50

Re: Help with something that should be obvious...
 
I'm actually quite pleased with this system, it's working exactly as I wanted it to.
Only up to 633 lines of code though, I expect this to at least double before I'm finished. :D
More info:
http://richard.phpfuture.net:8080/co...y?user=richard


All times are GMT. The time now is 03:23.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum