Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Help with something that should be obvious...

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

Help with something that should be obvious...
Reply
 
Thread Tools
Old 19-03-2005, 12:46   #1
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
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.
Richard M is offline   Reply With Quote
Advertisement
Old 19-03-2005, 13:39   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
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.

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
punky is offline   Reply With Quote
Old 19-03-2005, 13:49   #3
greencreeper
Inactive
 
Join Date: Nov 2003
Location: Leeds - the dog house
Age: 49
Services: Email me for a current price list
Posts: 8,270
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
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?
greencreeper is offline   Reply With Quote
Old 19-03-2005, 14:04   #4
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
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.
Richard M is offline   Reply With Quote
Old 19-03-2005, 15:06   #5
greencreeper
Inactive
 
Join Date: Nov 2003
Location: Leeds - the dog house
Age: 49
Services: Email me for a current price list
Posts: 8,270
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
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

I miss programming
greencreeper is offline   Reply With Quote
Old 19-03-2005, 15:50   #6
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
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.
More info:
http://richard.phpfuture.net:8080/co...y?user=richard
Richard M is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:42.


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