Page 1 of 1

HELP ME!

Posted: Mon Sep 20, 2010 4:07 am
by xDustin
Hey, I'm needing help. I'm stuck on something..

I'm wanting to do do this..


if $x is 15 less than $y then

I don't want it to be equal or less than because I've got something that updates every 5 seconds and if it doesn't update within 15 seconds it notifys me.

Re: HELP ME!

Posted: Mon Sep 20, 2010 4:22 am
by requinix
So what book are you trying to learn programming from?

Re: HELP ME!

Posted: Mon Sep 20, 2010 5:35 am
by xDustin
None? I'm just stumped on this part.

I'm wanting to check the "Last modified" time of a file on the server which I know how to,

but if the file hasn't been updated within "X" minutes/seconds whatever, I want it to notify me.

I know PHP, just this part is annoying me.

Re: HELP ME!

Posted: Mon Sep 20, 2010 6:10 am
by requinix
xDustin wrote:if $x is 15 less than $y then

Code: Select all

if ($x == $y - 15)
Surely I'm answering the wrong question.

Re: HELP ME!

Posted: Tue Sep 21, 2010 12:57 am
by xDustin
Wish it was that easy, but that doesn't work.. That is only if it's exactly 15 less. I'm wanting to do 15 or more/less

I've tried $x == $y > 15 etc but doesn't work.

What I'm exactly wanting to do is...

Code: Select all

<?PHP
$last_modified = date("i", filemtime("../images/Temp.jpg")); //Minute point file was last modified
$curr_time = date("i"); //Current Minute for server.

// If $last_modified is 15 OR more minutes behind $curr_time I want it to do what I want. 
?>

Re: HELP ME!

Posted: Tue Sep 21, 2010 1:46 am
by requinix
1. So it's actually neither the "if $x is 15 less than $y then" nor the "I'm wanting to do 15 or more/less" but
value A is no more than value B minus 15
2. Using date("i") is close but not what you want to be doing.

Code: Select all

<?PHP
$last_modified = filemtime("../images/Temp.jpg"); //Time file was last modified
$curr_time = time(); //Current Time for server.

// If $last_modified is 15 OR more minutes behind $curr_time I want it to do what I want.
if ($last_modified <= $curr_time * 15*60) {

Re: HELP ME!

Posted: Tue Sep 21, 2010 5:57 am
by xDustin
That looked promising, but it isn't working.

I've came up with a solution using the date() function, it works.

Code: Select all

<?php
$last_modified = date("i", filemtime("../images/Temp.jpg")); //Minute point file was last modified
$curr_time = date("i"); //Current Minute for server.

$diff = "";

if ($curr_time > $last_modified){
$diff = $curr_time - $last_modified;
}else if($last_modified > $curr_time){
$diff = $last_modified - $curr_time;
}

if ($diff > 5){
echo "Needs updated";
}else{
echo "Already updated";
}
?>